diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index 1a61236..714b366 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -414,7 +414,17 @@ export class AuthService { let userPayload: Record; let safeUser: any; - if (userId === '12345678-1234-1234-1234-123456789012') { + const user = await this.prisma.user.findUnique({ where: { id: userId } }); + if (user) { + userPayload = { + sub: user.id, + email: user.email, + phoneNumber: user.mobile, + role: user.role, + }; + const { password: _p, ...restUser } = user; + safeUser = restUser; + } else if (userId === '12345678-1234-1234-1234-123456789012') { if (process.env.NODE_ENV === 'production') { throw new UnauthorizedException('حساب کاربری مدیریت معتبر نیست'); } @@ -429,18 +439,7 @@ export class AuthService { role: 'Admin', }; } else { - const user = await this.prisma.user.findUnique({ where: { id: userId } }); - if (!user) { - throw new UnauthorizedException('کاربر یافت نشد'); - } - userPayload = { - sub: user.id, - email: user.email, - phoneNumber: user.mobile, - role: user.role, - }; - const { password: _p, ...restUser } = user; - safeUser = restUser; + throw new UnauthorizedException('کاربر یافت نشد'); } // Issue new pair of tokens diff --git a/backend/src/auth/jwt.strategy.ts b/backend/src/auth/jwt.strategy.ts index 7b42209..967874c 100644 --- a/backend/src/auth/jwt.strategy.ts +++ b/backend/src/auth/jwt.strategy.ts @@ -36,21 +36,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) { throw new UnauthorizedException('این توکن باطل شده است. لطفاً مجدداً وارد شوید'); } } - // Handle fallback admin ID only in non-production environments if ADMIN_EMAIL matches - if (payload.sub === '12345678-1234-1234-1234-123456789012') { - if (process.env.NODE_ENV === 'production') { - throw new UnauthorizedException('حساب کاربری مدیریت معتبر نیست'); - } - const adminEmail = process.env.ADMIN_EMAIL; - if (adminEmail && payload.email === adminEmail) { - return { - id: payload.sub, - email: adminEmail, - role: 'Admin', - }; - } - throw new UnauthorizedException('حساب کاربری مدیریت معتبر نیست'); - } const user = await this.usersService.findById(payload.sub); if (!user) {