fix: Add email uniqueness check to admin user seeding process

This commit is contained in:
Ayman
2026-07-08 07:17:39 +01:00
parent 7fbc2ea737
commit 2f5252faad
2 changed files with 17 additions and 2 deletions
+9
View File
@@ -58,10 +58,19 @@ const input = async (fieldName, options = {}) => {
validator.isEmail(process.env.DEFAULT_ADMIN_EMAIL) &&
process.env.DEFAULT_ADMIN_EMAIL.length <= 256
) {
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.');
}
process.env.DEFAULT_ADMIN_EMAIL = await input('Email', {
isRequired: true,
});
+6
View File
@@ -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();
if (userData.username) {