auth bug
This commit is contained in:
@@ -39,6 +39,11 @@ export class AuthService {
|
|||||||
async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
||||||
const { phone } = dto;
|
const { phone } = dto;
|
||||||
const normalizedPhone = normalizePhone(phone);
|
const normalizedPhone = normalizePhone(phone);
|
||||||
|
|
||||||
|
if (isAdmin) {
|
||||||
|
await this.valdateAdmin(normalizedPhone)
|
||||||
|
}
|
||||||
|
|
||||||
const code = this.generateOtpCode();
|
const code = this.generateOtpCode();
|
||||||
const key = isAdmin ? this.adminOtpKey(normalizedPhone) : this.userOtpKey(normalizedPhone);
|
const key = isAdmin ? this.adminOtpKey(normalizedPhone) : this.userOtpKey(normalizedPhone);
|
||||||
|
|
||||||
@@ -84,7 +89,7 @@ export class AuthService {
|
|||||||
if (cachedCode !== code) throw new BadRequestException('Invalid OTP');
|
if (cachedCode !== code) throw new BadRequestException('Invalid OTP');
|
||||||
await this.cacheService.del(key);
|
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) {
|
if (!admin) {
|
||||||
throw new BadRequestException(AuthMessage.ADMIN_NOT_FOUND);
|
throw new BadRequestException(AuthMessage.ADMIN_NOT_FOUND);
|
||||||
@@ -105,4 +110,12 @@ export class AuthService {
|
|||||||
refreshToken(oldRefreshToken: string) {
|
refreshToken(oldRefreshToken: string) {
|
||||||
return this.tokensService.refreshToken(oldRefreshToken);
|
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 {
|
export interface AdminLoginResponse {
|
||||||
id: string;
|
|
||||||
firstName?: string;
|
firstName?: string;
|
||||||
lastName?: string;
|
lastName?: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
@@ -15,7 +14,6 @@ export class AdminLoginTransformer {
|
|||||||
static async transform(admin: Admin): Promise<AdminLoginResponse> {
|
static async transform(admin: Admin): Promise<AdminLoginResponse> {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: admin.id,
|
|
||||||
firstName: admin.firstName,
|
firstName: admin.firstName,
|
||||||
lastName: admin.lastName,
|
lastName: admin.lastName,
|
||||||
phone: admin.phone,
|
phone: admin.phone,
|
||||||
|
|||||||
Reference in New Issue
Block a user