fix: Add username uniqueness check to admin user seeding

This commit is contained in:
Ayman
2026-07-08 07:17:32 +01:00
parent 0a2641db84
commit 7fbc2ea737
2 changed files with 23 additions and 5 deletions
+13 -5
View File
@@ -97,12 +97,20 @@ const input = async (fieldName, options = {}) => {
USERNAME_REGEX.test(process.env.DEFAULT_ADMIN_USERNAME);
if (isValid) {
break;
}
const existingUser = await knex('user_account')
.where('username', process.env.DEFAULT_ADMIN_USERNAME.toLowerCase())
.first();
console.log(
'Username must be 3-32 characters and contain only letters, digits, underscores, and dots (e.g., john_doe).',
);
if (!existingUser) {
break;
}
console.log('Username is already in use.');
} else {
console.log(
'Username must be 3-32 characters and contain only letters, digits, underscores, and dots (e.g., john_doe).',
);
}
process.env.DEFAULT_ADMIN_USERNAME = await input('Username');