Skip to content

Commit

Permalink
Merge pull request spacebarchat#1179 from DEVTomatoCake/fix/consisten…
Browse files Browse the repository at this point in the history
…t-username-length-requirements

Consistent username length requirement
  • Loading branch information
MaddyUnderStars authored Aug 18, 2024
2 parents bb31df0 + 95bbccb commit 1f0c41a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
16 changes: 13 additions & 3 deletions src/api/routes/auth/register.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -287,6 +287,16 @@ router.post(
});
}

const { maxUsername } = Config.get().limits.user;
if (body.username.length > maxUsername) {
throw FieldErrors({
username: {
code: "BASE_TYPE_BAD_LENGTH",
message: `Must be between 2 and ${maxUsername} in length.`,
},
});
}

const user = await User.register({ ...body, req });

if (body.invite) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/routes/users/@me/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ router.patch(
if (check_username.length > maxUsername) {
throw FieldErrors({
username: {
code: "USERNAME_INVALID",
message: `Username must be less than ${maxUsername} in length`,
code: "BASE_TYPE_BAD_LENGTH",
message: `Must be between 2 and ${maxUsername} in length.`,
},
});
}
Expand Down
7 changes: 3 additions & 4 deletions src/util/schemas/RegisterSchema.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

export interface RegisterSchema {
/**
* @minLength 2
* @maxLength 32
*/
username: string;
/**
Expand Down
3 changes: 1 addition & 2 deletions src/util/schemas/UserModifySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

export interface UserModifySchema {
/**
* @minLength 1
* @maxLength 100
* @minLength 2
*/
username?: string;
avatar?: string | null;
Expand Down

0 comments on commit 1f0c41a

Please sign in to comment.