From b4139283e153524f2bd0fcd11c44dde780852e10 Mon Sep 17 00:00:00 2001 From: cherif Date: Tue, 17 Jan 2023 11:08:34 +0100 Subject: [PATCH] different new username when another one exist at the first connection --- .../nestjs/api_back/src/auth/42/authentication.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/srcs/requirements/nestjs/api_back/src/auth/42/authentication.service.ts b/srcs/requirements/nestjs/api_back/src/auth/42/authentication.service.ts index b338ce7b..3d4098ac 100644 --- a/srcs/requirements/nestjs/api_back/src/auth/42/authentication.service.ts +++ b/srcs/requirements/nestjs/api_back/src/auth/42/authentication.service.ts @@ -24,10 +24,12 @@ export class AuthenticationService { if (!check_name) return await this.userService.create(createUsersDto); let createUsersDtoWithUsername : CreateUsersDto = createUsersDto; + let i = 0; while (check_name === true) { - createUsersDtoWithUsername = { ...createUsersDto, username: createUsersDto.username + randomUUID() }; + createUsersDtoWithUsername = { ...createUsersDto, username: createUsersDto.username + '_' + i}; check_name = await this.userService.isUsernameExists(createUsersDtoWithUsername.username); + i++; } return this.userService.create(createUsersDtoWithUsername); }