auth bug
This commit is contained in:
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<AdminLoginResponse> {
|
||||
|
||||
return {
|
||||
id: admin.id,
|
||||
firstName: admin.firstName,
|
||||
lastName: admin.lastName,
|
||||
phone: admin.phone,
|
||||
|
||||
Reference in New Issue
Block a user