From d88e9273ffcc95477e560e7b1a3bd32011e24f6c Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Fri, 8 Sep 2023 22:38:56 -0400 Subject: fix being able to register with taken username --- src/util/entities/User.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/util') diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index 5ec9862e..07b68b6d 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts @@ -379,7 +379,7 @@ export class User extends BaseClass { if (uniqueUsernames) { // check if there is already an account with this username - if (!User.isUsernameAvailable(username)) + if (!(await User.isUsernameAvailable(username))) throw FieldErrors({ username: { code: "USERNAME_ALREADY_TAKEN", @@ -463,11 +463,14 @@ export class User extends BaseClass { } static async isUsernameAvailable(username: string) { - const user = await User.findOne({ - where: { username }, - select: ["id"], + // TODO: implement regex check? + const count = await User.count({ + where: { + username: username.toLowerCase(), + }, }); - return !user; + + return count === 0; } } -- cgit 1.5.1