fix: Add email uniqueness check to admin user seeding process
This commit is contained in:
@@ -58,10 +58,19 @@ const input = async (fieldName, options = {}) => {
|
|||||||
validator.isEmail(process.env.DEFAULT_ADMIN_EMAIL) &&
|
validator.isEmail(process.env.DEFAULT_ADMIN_EMAIL) &&
|
||||||
process.env.DEFAULT_ADMIN_EMAIL.length <= 256
|
process.env.DEFAULT_ADMIN_EMAIL.length <= 256
|
||||||
) {
|
) {
|
||||||
break;
|
const existingUser = await knex('user_account')
|
||||||
|
.where('email', process.env.DEFAULT_ADMIN_EMAIL.toLowerCase())
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (!existingUser) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Email is already in use.');
|
||||||
|
} else {
|
||||||
|
console.log('Email must be a valid e-mail address with no more than 256 characters.');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Email must be a valid e-mail address with no more than 256 characters.');
|
|
||||||
process.env.DEFAULT_ADMIN_EMAIL = await input('Email', {
|
process.env.DEFAULT_ADMIN_EMAIL = await input('Email', {
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ exports.seed = async (knex) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const existingEmailUser = await knex('user_account').where('email', defaultAdminEmail).first();
|
||||||
|
|
||||||
|
if (existingEmailUser) {
|
||||||
|
throw new Error(`User with DEFAULT_ADMIN_EMAIL "${defaultAdminEmail}" already exists.`);
|
||||||
|
}
|
||||||
|
|
||||||
const userData = buildUserData();
|
const userData = buildUserData();
|
||||||
|
|
||||||
if (userData.username) {
|
if (userData.username) {
|
||||||
|
|||||||
Reference in New Issue
Block a user