From da298a33500249486141c6bb5bc80e0c468da452 Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Sat, 30 May 2026 11:37:09 +0330 Subject: [PATCH] Showing a valid message while the OTP is still valid, instead of 400 --- src/.env.example => .env.example | 0 src/auth/auth-controllers/user/user.auth.controller.ts | 1 + src/auth/auth-services/user-auth-error.ts | 6 +++--- src/auth/auth-services/user.auth.service.ts | 3 ++- src/auth/dto/user/login.dto.ts | 6 +++++- 5 files changed, 11 insertions(+), 5 deletions(-) rename src/.env.example => .env.example (100%) diff --git a/src/.env.example b/.env.example similarity index 100% rename from src/.env.example rename to .env.example diff --git a/src/auth/auth-controllers/user/user.auth.controller.ts b/src/auth/auth-controllers/user/user.auth.controller.ts index 732c483..fee6fad 100644 --- a/src/auth/auth-controllers/user/user.auth.controller.ts +++ b/src/auth/auth-controllers/user/user.auth.controller.ts @@ -30,6 +30,7 @@ export class UserAuthController { linkToken: body.linkToken, linkContext: body.linkContext, }); + if (res) { throw new HttpException(res, HttpStatus.ACCEPTED); } diff --git a/src/auth/auth-services/user-auth-error.ts b/src/auth/auth-services/user-auth-error.ts index e663ea4..efc2de4 100644 --- a/src/auth/auth-services/user-auth-error.ts +++ b/src/auth/auth-services/user-auth-error.ts @@ -34,9 +34,9 @@ export function userAuthErrorBody(code: UserAuthErrorCode) { } export function throwUserAuthError(code: UserAuthErrorCode): never { - if (code === UserAuthErrorCode.OTP_REQUEST_TOO_SOON) { - throw new BadRequestException(userAuthErrorBody(code)); - } + // if (code === UserAuthErrorCode.OTP_REQUEST_TOO_SOON) { + // throw new BadRequestException(userAuthErrorBody(code)); + // } if (code === UserAuthErrorCode.LINK_MOBILE_MISMATCH) { throw new ForbiddenException(userAuthErrorBody(code)); diff --git a/src/auth/auth-services/user.auth.service.ts b/src/auth/auth-services/user.auth.service.ts index c6b505e..abf038f 100644 --- a/src/auth/auth-services/user.auth.service.ts +++ b/src/auth/auth-services/user.auth.service.ts @@ -139,7 +139,8 @@ export class UserAuthService { } if (isOtpExpiryActive(userExist.otpExpire, nowMs)) { - throwUserAuthError(UserAuthErrorCode.OTP_REQUEST_TOO_SOON); + // throwUserAuthError(UserAuthErrorCode.OTP_REQUEST_TOO_SOON); + return new LoginDtoRs(userExist, "OTP Still valid"); } await this.smsSender(otp, canonicalMobile); diff --git a/src/auth/dto/user/login.dto.ts b/src/auth/dto/user/login.dto.ts index 9340863..ad25b8a 100644 --- a/src/auth/dto/user/login.dto.ts +++ b/src/auth/dto/user/login.dto.ts @@ -35,7 +35,9 @@ export class UserLoginDto { } export class LoginDtoRs extends UserModel { + @ApiProperty({ type: "string" }) message: string; + @ApiProperty({ example: "09226187419", type: "string", @@ -61,8 +63,10 @@ export class LoginDtoRs extends UserModel { username: string; mobile: string; nationalCode: string; - constructor(loginData) { + + constructor(loginData, message: string = "") { super(); this.mobile = loginData.mobile; + this.message = message; } }