From 58664e01d61c898d36f06be8fd1cc1772ddffda2 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 22 Feb 2024 19:44:45 +0200 Subject: [PATCH] update: updated username check --- server/src/modules/auth/base/auth.service.ts | 28 +++++++++---------- .../modules/auth/base/dto/auth-update.dto.ts | 2 ++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/server/src/modules/auth/base/auth.service.ts b/server/src/modules/auth/base/auth.service.ts index 70497de5..0344388e 100644 --- a/server/src/modules/auth/base/auth.service.ts +++ b/server/src/modules/auth/base/auth.service.ts @@ -397,17 +397,17 @@ export class AuthService { ); } - if (userDto.username && !this.isUsernameAllowed(userDto.username)) { - throw new HttpException( - { - status: HttpStatus.UNPROCESSABLE_ENTITY, - errors: { - username: 'invalid', - }, - }, - HttpStatus.UNPROCESSABLE_ENTITY - ); - } + // 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: { @@ -423,9 +423,9 @@ export class AuthService { }); } - private isUsernameAllowed(username: string) { - return /^[A-Za-z0-9]+$/.test(username); - } + // private isUsernameAllowed(username: string) { + // return /^[A-Za-z0-9]+$/.test(username); + // } async refreshToken( data: Pick diff --git a/server/src/modules/auth/base/dto/auth-update.dto.ts b/server/src/modules/auth/base/dto/auth-update.dto.ts index 606e3e2e..9ef13daa 100644 --- a/server/src/modules/auth/base/dto/auth-update.dto.ts +++ b/server/src/modules/auth/base/dto/auth-update.dto.ts @@ -1,5 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { + IsAlphanumeric, IsArray, IsIn, IsNotEmpty, @@ -43,6 +44,7 @@ export class AuthUpdateDto { @Validate(IsNotExist, ['User'], { message: 'usernameAlreadyExists', }) + @IsAlphanumeric() username?: string | null; @ApiProperty()