fix: prevent admin from login to console of user

This commit is contained in:
mahyargdz
2025-02-19 15:09:04 +03:30
parent 95e22e0886
commit 10825e5988
2 changed files with 7 additions and 1 deletions
+2 -1
View File
@@ -53,7 +53,8 @@ export const enum AuthMessage {
TOO_MANY_REQUESTS = "تعداد درخواست های شما بیش از حد مجاز است",
NOT_ADMIN = "شما دسترسی به بخش ادمین ندارید",
PHONE_SHOULD_BE_11_DIGIT = "شماره تلفن باید ۱۱ رقم باشد",
TIMESTAMP_NOT_EMPTY = "TIMESTAMP_NOT_EMPTY",
TIMESTAMP_NOT_EMPTY = "زمان نمی‌تواند خالی باشد",
ADMIN_CAN_NOT_LOGIN = "ادمین نمی‌تواند وارد شود",
}
export const enum UserMessage {
@@ -91,6 +91,8 @@ export class AuthService {
const user = await this.checkUserLoginCredentialWithEmail(email, password);
if (!user.roles.some((role) => !role.isAdmin)) throw new BadRequestException(AuthMessage.ADMIN_CAN_NOT_LOGIN);
const tokens = this.generateAccessAndRefreshToken(user);
await this.notificationService.createLoginNotification(user.id);
@@ -169,6 +171,9 @@ export class AuthService {
const user = await this.checkUserLoginCredentialWithPhone(phone, code);
if (!user.roles.some((role) => !role.isAdmin)) throw new BadRequestException(AuthMessage.ADMIN_CAN_NOT_LOGIN);
// if (user.roles.some((role) => role.isAdmin)) throw new BadRequestException(AuthMessage.ADMIN_CAN_NOT_LOGIN);
const tokens = this.generateAccessAndRefreshToken(user);
await this.notificationService.createLoginNotification(user.id);