Skip to content

Commit 85435b7

Browse files
committed
fix being able to register with taken username
1 parent dbb5759 commit 85435b7

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/api/routes/experiments.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ router.get("/", route({}), (req: Request, res: Response) => {
3535
if (uniqueUsernames) {
3636
// hash, revision, bucket, override, population, hash_result, as_mode
3737
// bucket 4 is used by the official client, and enables live checking and suggestions, 3 is only live checking
38-
data.assignments.push([2476969328, 0, 3, -1, 0, 9267, 0, 0]);
38+
data.assignments.push([2476969328, 0, 4, -1, 0, 9267, 0, 0]);
3939
}
4040
res.send(data);
4141
});

src/api/routes/unique-username/username-attempt-unauthed.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ router.post(
2525
}
2626

2727
res.json({
28-
taken: !User.isUsernameAvailable(body.username),
28+
taken: !(await User.isUsernameAvailable(body.username)),
2929
});
3030
},
3131
);

src/api/routes/users/@me/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ router.patch(
172172
}
173173

174174
// check if username is already taken (pomelo only)
175-
if (!User.isUsernameAvailable(body.username))
175+
if (!(await User.isUsernameAvailable(body.username)))
176176
throw FieldErrors({
177177
username: {
178178
code: "USERNAME_ALREADY_TAKEN",

src/util/entities/User.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export class User extends BaseClass {
379379

380380
if (uniqueUsernames) {
381381
// check if there is already an account with this username
382-
if (!User.isUsernameAvailable(username))
382+
if (!(await User.isUsernameAvailable(username)))
383383
throw FieldErrors({
384384
username: {
385385
code: "USERNAME_ALREADY_TAKEN",
@@ -463,11 +463,14 @@ export class User extends BaseClass {
463463
}
464464

465465
static async isUsernameAvailable(username: string) {
466-
const user = await User.findOne({
467-
where: { username },
468-
select: ["id"],
466+
// TODO: implement regex check?
467+
const count = await User.count({
468+
where: {
469+
username: username.toLowerCase(),
470+
},
469471
});
470-
return !user;
472+
473+
return count === 0;
471474
}
472475
}
473476

0 commit comments

Comments
 (0)