fix: auth

This commit is contained in:
mahyargdz
2025-06-01 10:35:35 +03:30
parent f56e9449d9
commit afa2f0036b
+6 -2
View File
@@ -61,12 +61,16 @@ export class AuthService {
await entityManager.begin(); 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 hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password);
const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, business, entityManager); 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"); await this.otpService.delOtpFormCache(phone, "REGISTER");
const tokens = await this.tokensService.generateTokens(user, entityManager); const tokens = await this.tokensService.generateTokens(user, entityManager);