From d221599238a65dd6347d4a4d63b090c77addaaad Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Wed, 14 Jan 2026 19:14:58 +0330 Subject: [PATCH] auth bug --- src/modules/auth/services/auth.service.ts | 15 ++++++++++++++- .../auth/transformers/admin-login.transformer.ts | 2 -- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/modules/auth/services/auth.service.ts b/src/modules/auth/services/auth.service.ts index cedcdaf..b06ad6c 100644 --- a/src/modules/auth/services/auth.service.ts +++ b/src/modules/auth/services/auth.service.ts @@ -39,6 +39,11 @@ export class AuthService { async requestOtp(dto: RequestOtpDto, isAdmin: boolean) { const { phone } = dto; const normalizedPhone = normalizePhone(phone); + + if (isAdmin) { + await this.valdateAdmin(normalizedPhone) + } + const code = this.generateOtpCode(); const key = isAdmin ? this.adminOtpKey(normalizedPhone) : this.userOtpKey(normalizedPhone); @@ -84,7 +89,7 @@ export class AuthService { if (cachedCode !== code) throw new BadRequestException('Invalid OTP'); await this.cacheService.del(key); - const admin = await this.adminRepository.findOne({ phone: normalizedPhone }); + const admin = await this.adminRepository.findOne({ phone: normalizedPhone }, { populate: ['role', 'role.permissions'] }); if (!admin) { throw new BadRequestException(AuthMessage.ADMIN_NOT_FOUND); @@ -105,4 +110,12 @@ export class AuthService { refreshToken(oldRefreshToken: string) { return this.tokensService.refreshToken(oldRefreshToken); } + + private async valdateAdmin(phone: string) { + const admin = await this.adminRepository.findOne({ phone }) + if (!admin) { + throw new BadRequestException('Admin Not Found') + } + } + } diff --git a/src/modules/auth/transformers/admin-login.transformer.ts b/src/modules/auth/transformers/admin-login.transformer.ts index 26ab024..5c467e8 100644 --- a/src/modules/auth/transformers/admin-login.transformer.ts +++ b/src/modules/auth/transformers/admin-login.transformer.ts @@ -2,7 +2,6 @@ import type { Admin } from '../../admin/entities/admin.entity'; export interface AdminLoginResponse { - id: string; firstName?: string; lastName?: string; phone: string; @@ -15,7 +14,6 @@ export class AdminLoginTransformer { static async transform(admin: Admin): Promise { return { - id: admin.id, firstName: admin.firstName, lastName: admin.lastName, phone: admin.phone,