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
+11 -2
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
) {
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', {
isRequired: true,
});