From eb2bb2414131815dc18c0044118ed9461c7ce700 Mon Sep 17 00:00:00 2001 From: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Date: Thu, 17 Feb 2022 22:18:27 +0800 Subject: [PATCH] validate first user email during installation (#11682) --- api/src/cli/commands/init/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/src/cli/commands/init/index.ts b/api/src/cli/commands/init/index.ts index c0232737e4..5067316b2a 100644 --- a/api/src/cli/commands/init/index.ts +++ b/api/src/cli/commands/init/index.ts @@ -4,6 +4,7 @@ import inquirer from 'inquirer'; import { Knex } from 'knex'; import ora from 'ora'; import { v4 as uuidV4 } from 'uuid'; +import Joi from 'joi'; import runMigrations from '../../../database/migrations/run'; import runSeed from '../../../database/seeds/run'; import createDBConnection, { Credentials } from '../../utils/create-db-connection'; @@ -75,6 +76,12 @@ export default async function init(): Promise { name: 'email', message: 'Email', default: 'admin@example.com', + validate: (input: string) => { + const emailSchema = Joi.string().email().required(); + const { error } = emailSchema.validate(input); + if (error) throw new Error('The email entered is not a valid email address!'); + return true; + }, }, { type: 'password',