diff --git a/src/modules/auth/providers/auth.service.ts b/src/modules/auth/providers/auth.service.ts index 56c7ca7..3cb1411 100755 --- a/src/modules/auth/providers/auth.service.ts +++ b/src/modules/auth/providers/auth.service.ts @@ -61,12 +61,16 @@ export class AuthService { await entityManager.begin(); // + const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER"); + if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP); + + const existUser = await this.usersService.findOneWithPhone(phone, business.id); + if (existUser) throw new BadRequestException(AuthMessage.PHONE_EXISTS); + const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password); const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, business, entityManager); - const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER"); - if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP); await this.otpService.delOtpFormCache(phone, "REGISTER"); const tokens = await this.tokensService.generateTokens(user, entityManager);