fixed forgot password

This commit is contained in:
unknown
2024-10-21 14:44:39 +03:00
parent 1054ac6053
commit fa35c2c60c
2 changed files with 19 additions and 13 deletions

View File

@ -210,7 +210,7 @@ export class UserAuthService {
}
const otpCode = Math.floor(100000 + Math.random() * 900000).toString();
const expiryTime = new Date();
expiryTime.setMinutes(expiryTime.getMinutes() + 1);
expiryTime.setMinutes(expiryTime.getMinutes() + 10);
await this.otpRepository.save({
email: data.email,
otpCode,
@ -232,7 +232,10 @@ export class UserAuthService {
return { otpCode, cooldown };
}
async verifyOTP(data: VerifyOtpDto): Promise<boolean> {
async verifyOTP(
data: VerifyOtpDto,
fromNewPassword: boolean = false,
): Promise<boolean> {
const otp = await this.otpRepository.findOne({
where: { email: data.email, type: data.type },
});
@ -253,7 +256,7 @@ export class UserAuthService {
throw new BadRequestException('You entered wrong otp');
}
if (otp.expiryTime < new Date()) {
if (otp.expiryTime < new Date() || fromNewPassword) {
await this.otpRepository.delete(otp.uuid);
throw new BadRequestException('OTP expired');
}