diff --git a/src/modules/auth/providers/auth.service.ts b/src/modules/auth/providers/auth.service.ts index 4e25c17..a702135 100755 --- a/src/modules/auth/providers/auth.service.ts +++ b/src/modules/auth/providers/auth.service.ts @@ -61,10 +61,11 @@ export class AuthService { await queryRunner.startTransaction(); // const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER"); - if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP); - await this.otpService.delOtpFormCache(phone, "REGISTER"); + const existUser = await this.usersService.findOneWithPhone(phone); + if (existUser) throw new BadRequestException(AuthMessage.PHONE_EXISTS); + const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password); const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, queryRunner); @@ -83,6 +84,8 @@ export class AuthService { }); } + await this.otpService.delOtpFormCache(phone, "REGISTER"); + await queryRunner.commitTransaction(); return {