summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-09-08 22:38:56 -0400
committerRory& <root@rory.gay>2026-01-21 07:10:11 +0100
commitc5d28482bf7ff0490bc41904ccb4ea74e5d602dc (patch)
tree371a047d4e5afac0988b81cc5620ccf1b7b69da2 /src/util
parentadd unique-username routes to unauthenticated list (diff)
downloadserver-ts-c5d28482bf7ff0490bc41904ccb4ea74e5d602dc.tar.xz
fix being able to register with taken username
Diffstat (limited to 'src/util')
-rw-r--r--src/util/entities/User.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts

index 49de9fee..dd66f7d2 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts
@@ -318,7 +318,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", @@ -439,10 +439,13 @@ 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; } }