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')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user