This commit is contained in:
SepehrYahyaee
2026-06-23 10:26:51 +03:30
parent c6b417ced7
commit ed2b6948cf
3 changed files with 27 additions and 1 deletions

View File

@@ -13,6 +13,8 @@ import {
} from "src/helpers/iran-mobile";
import {
computeOtpExpireMs,
FAKE_OTP_CODE,
isFakeOtpEnabled,
isOtpExpiryActive,
readOtpExpireMinutesFromEnv,
} from "src/helpers/user-otp-expiry";
@@ -109,7 +111,7 @@ export class UserAuthService {
const userExist = await this.userDbService.findOne(
buildUserLookupByPhone(canonicalMobile),
);
const otp = this.otpCreator.create();
const otp = this.createOtpForRequest();
const hashOtp = await this.hashService.hash(otp);
const expireMinutes = readOtpExpireMinutesFromEnv();
const nowMs = Date.now();
@@ -158,7 +160,23 @@ export class UserAuthService {
return new LoginDtoRs(userExist);
}
private createOtpForRequest(): string {
if (isFakeOtpEnabled()) {
this.logger.warn(
"FAKE_OTP=true — using fixed dev OTP; SMS provider is not called",
);
return FAKE_OTP_CODE;
}
return this.otpCreator.create();
}
private async smsSender(otp: string, mobile: string) {
if (isFakeOtpEnabled()) {
this.logger.log(
`FAKE_OTP=true — skipped SMS for phone=${mobile} (use OTP ${FAKE_OTP_CODE})`,
);
return;
}
const ok = await this.smsOrchestrationService.sendAuthOtp(
mobile,
otp,