security(auth): remove OTP console log and hardcoded admin credentials [TASK-26.4] [TASK-26.5]

This commit is contained in:
parsa aghaei committed 2026-08-05 14:38:57 +03:30
1 parent 3fe379a1d2
commit 350182c5a4
2 files changed
+27 -7

No files matched your search

+25 -5
View File
@@ -20,7 +20,6 @@ export class AuthService {
const { phoneNumber } = sendOtpDto;
const code = Math.floor(10000 + Math.random() * 90000).toString();
console.log(`[SMS OTP] Code for ${phoneNumber}: ${code}`);
await this.redisService.set(`otp:${phoneNumber}`, code, 120);
@@ -169,10 +168,30 @@ export class AuthService {
}
async adminLogin(body: any) {
if (
body.email === 'admin@canino-iran.com' &&
body.password === 'admin123'
) {
const adminEmail = process.env.ADMIN_EMAIL || 'admin@canina-iran.com';
const adminPassword = process.env.ADMIN_PASSWORD || 'admin123';
// First check database for user with role 'Admin' or 'SUPER_ADMIN'
const dbAdmin = await this.prisma.user.findFirst({
where: { email: body.email, role: { in: ['Admin', 'SUPER_ADMIN', 'ADMIN'] } },
});
if (dbAdmin && dbAdmin.password) {
const isMatch = await bcrypt.compare(body.password, dbAdmin.password);
if (isMatch) {
const payload = { sub: dbAdmin.id, email: dbAdmin.email, role: dbAdmin.role };
return {
success: true,
data: {
user: dbAdmin,
accessToken: this.jwtService.sign(payload),
},
};
}
}
// Fallback to validated environment variable credentials
if (body.email === adminEmail && body.password === adminPassword) {
const payload = {
sub: '12345678-1234-1234-1234-123456789012',
email: body.email,
@@ -190,6 +209,7 @@ export class AuthService {
},
};
}
throw new BadRequestException({
message: 'ایمیل یا رمز عبور اشتباه است',
error: 'INVALID_CREDENTIALS',