Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
update: added username check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Sai committed Feb 19, 2024
1 parent 28693d9 commit b788340
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/src/modules/auth/base/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ export class AuthService {
);
}

if (userDto.username && !this.isUsernameAllowed(userDto.username)) {
throw new HttpException(
{
status: HttpStatus.UNPROCESSABLE_ENTITY,
errors: {
username: 'invalid',
},
},
HttpStatus.UNPROCESSABLE_ENTITY
);
}

await this.sessionService.softDelete({
user: {
id: currentUser.id,
Expand All @@ -411,6 +423,10 @@ export class AuthService {
});
}

private isUsernameAllowed(username: string) {
return /^[A-Za-z0-9]+$/.test(username);
}

async refreshToken(
data: Pick<JwtRefreshPayloadType, 'sessionId'>
): Promise<Omit<LoginResponseType, 'user'>> {
Expand Down

0 comments on commit b788340

Please sign in to comment.