diff --git a/src/api/routes/experiments.ts b/src/api/routes/experiments.ts index da83a1c91..015ac16ec 100644 --- a/src/api/routes/experiments.ts +++ b/src/api/routes/experiments.ts @@ -35,7 +35,7 @@ router.get("/", route({}), (req: Request, res: Response) => { if (uniqueUsernames) { // hash, revision, bucket, override, population, hash_result, as_mode // bucket 4 is used by the official client, and enables live checking and suggestions, 3 is only live checking - data.assignments.push([2476969328, 0, 3, -1, 0, 9267, 0, 0]); + data.assignments.push([2476969328, 0, 4, -1, 0, 9267, 0, 0]); } res.send(data); }); diff --git a/src/api/routes/unique-username/username-attempt-unauthed.ts b/src/api/routes/unique-username/username-attempt-unauthed.ts index a1f63a691..3af1fa883 100644 --- a/src/api/routes/unique-username/username-attempt-unauthed.ts +++ b/src/api/routes/unique-username/username-attempt-unauthed.ts @@ -25,7 +25,7 @@ router.post( } res.json({ - taken: !User.isUsernameAvailable(body.username), + taken: !(await User.isUsernameAvailable(body.username)), }); }, ); diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts index ec0a050a8..9601005e6 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts @@ -152,7 +152,7 @@ router.patch( } // check if username is already taken (pomelo only) - if (!User.isUsernameAvailable(body.username)) + if (!(await User.isUsernameAvailable(body.username))) throw FieldErrors({ username: { code: "USERNAME_ALREADY_TAKEN", diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index 49de9feee..dd66f7d26 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; } }