تغییرات کلی در backend و frontend

This commit is contained in:
parsa aghaei committed 2026-07-11 12:30:17 +03:30
1 parent a74f4bda48
commit 3dedc89ee1
41 files changed
+2373 -1957

No files matched your search

+6 -3
View File
@@ -53,13 +53,16 @@ describe('AuthService', () => {
});
describe('sendOtp', () => {
it('should generate a 5 digit OTP and save it in Redis', async () => {
it('should generate a 5 digit OTP, save it in Redis, and not expose it in response', async () => {
const result = await service.sendOtp({ phoneNumber: '09123456789' });
expect(result.success).toBe(true);
expect(result.code).toHaveLength(5);
expect(result.message).toBe('کد تایید ارسال شد');
// Code should NOT be in the response (security)
expect((result as any).code).toBeUndefined();
// But it should have been stored in Redis
expect(redis.set).toHaveBeenCalledWith(
'otp:09123456789',
result.code,
expect.stringMatching(/^\d{5}$/),
120,
);
});
+4 -2
View File
@@ -18,11 +18,13 @@ export class AuthService {
const { phoneNumber } = sendOtpDto;
const code = Math.floor(10000 + Math.random() * 90000).toString();
console.log(`[Mock SMS] Sending OTP ${code} to ${phoneNumber}`);
// In production: replace this log with a real SMS provider (e.g. KaveNegar, Melipayamak)
console.log(`[Dev SMS] OTP for ${phoneNumber}: ${code}`);
await this.redisService.set(`otp:${phoneNumber}`, code, 120);
return { success: true, message: 'کد تایید ارسال شد', code };
// SECURITY: Never return the OTP code in the response
return { success: true, message: 'کد تایید ارسال شد' };
}
async verifyOtp(verifyOtpDto: VerifyOtpDto) {