Updated With Dev Login
This commit is contained in:
parent
2693469217
commit
6606ed23e3
|
|
@ -1 +1 @@
|
||||||
Subproject commit f5b5389b3b603798529c9209547fef836cef0a1f
|
Subproject commit 62b2750d6ed295df1b9a062a4834b06213d240e0
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const db = require('../db');
|
const db = require('../db');
|
||||||
|
const config = require('../config');
|
||||||
const { sendOtpSms } = require('../services/smsService');
|
const { sendOtpSms } = require('../services/smsService');
|
||||||
const { createOtp, verifyOtp } = require('../services/otpService');
|
const { createOtp, verifyOtp } = require('../services/otpService');
|
||||||
const {
|
const {
|
||||||
|
|
@ -711,7 +712,7 @@ router.post(
|
||||||
console.log(`[AUTH] Token refresh: userId=${userId}, deviceId=${deviceId}, ip=${clientIp}`);
|
console.log(`[AUTH] Token refresh: userId=${userId}, deviceId=${deviceId}, ip=${clientIp}`);
|
||||||
|
|
||||||
const newAccess = signAccessToken(user, { highAssurance: hasRecentOtp });
|
const newAccess = signAccessToken(user, { highAssurance: hasRecentOtp });
|
||||||
console.log(`[AUTH] New access token generated: userId=${userId}, expiresIn=${ACCESS_TTL}`);
|
console.log(`[AUTH] New access token generated: userId=${userId}, expiresIn=${config.jwtAccessTtl}`);
|
||||||
|
|
||||||
const newRefresh = await rotateRefreshToken({
|
const newRefresh = await rotateRefreshToken({
|
||||||
tokenRow,
|
tokenRow,
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,20 @@ function generateOtpCode() {
|
||||||
* @returns {Promise<{code: string}>} - The generated OTP code
|
* @returns {Promise<{code: string}>} - The generated OTP code
|
||||||
*/
|
*/
|
||||||
async function createOtp(phoneNumber) {
|
async function createOtp(phoneNumber) {
|
||||||
const code = generateOtpCode();
|
// === DEBUGGING: TEST OTP BYPASS ===
|
||||||
|
// For testing purposes, always generate OTP "123456" for phone number "1234567890"
|
||||||
|
// Handle both formats: "1234567890" (raw) and "+911234567890" (normalized)
|
||||||
|
const testPhoneNumbers = ["1234567890", "+911234567890"];
|
||||||
|
const testOtpCode = "123456";
|
||||||
|
const normalizedPhone = phoneNumber.trim();
|
||||||
|
|
||||||
|
// Use test OTP code for test phone number
|
||||||
|
const code = testPhoneNumbers.includes(normalizedPhone) ? testOtpCode : generateOtpCode();
|
||||||
|
|
||||||
|
if (testPhoneNumbers.includes(normalizedPhone)) {
|
||||||
|
console.log('[OTP Service] 🔧 DEBUG MODE: Test OTP generated for phone:', normalizedPhone, '- Code:', testOtpCode);
|
||||||
|
}
|
||||||
|
|
||||||
const expiresAt = new Date(Date.now() + OTP_EXPIRY_MS);
|
const expiresAt = new Date(Date.now() + OTP_EXPIRY_MS);
|
||||||
const otpHash = await bcrypt.hash(code, 10);
|
const otpHash = await bcrypt.hash(code, 10);
|
||||||
|
|
||||||
|
|
@ -103,6 +116,23 @@ async function createOtp(phoneNumber) {
|
||||||
* - All code paths take similar execution time regardless of outcome
|
* - All code paths take similar execution time regardless of outcome
|
||||||
*/
|
*/
|
||||||
async function verifyOtp(phoneNumber, code) {
|
async function verifyOtp(phoneNumber, code) {
|
||||||
|
// === DEBUGGING: TEST OTP BYPASS ===
|
||||||
|
// For testing purposes, allow OTP "123456" for phone number "1234567890"
|
||||||
|
// Handle both formats: "1234567890" (raw) and "+911234567890" (normalized)
|
||||||
|
const testPhoneNumbers = ["1234567890", "+911234567890"];
|
||||||
|
const testOtpCode = "123456";
|
||||||
|
|
||||||
|
// Normalize code to string for comparison (handles both string and number inputs)
|
||||||
|
const codeStr = String(code).trim();
|
||||||
|
const normalizedPhone = phoneNumber.trim();
|
||||||
|
|
||||||
|
// Check if this is a test phone number with test OTP code
|
||||||
|
if (testPhoneNumbers.includes(normalizedPhone) && codeStr === testOtpCode) {
|
||||||
|
console.log('[OTP Service] 🔧 DEBUG MODE: Test OTP bypass activated for phone:', normalizedPhone);
|
||||||
|
// Return success immediately without database check
|
||||||
|
return { ok: true };
|
||||||
|
}
|
||||||
|
|
||||||
// === SECURITY HARDENING: FIELD-LEVEL ENCRYPTION ===
|
// === SECURITY HARDENING: FIELD-LEVEL ENCRYPTION ===
|
||||||
// For search, we need to handle encrypted phone numbers
|
// For search, we need to handle encrypted phone numbers
|
||||||
// Since encryption uses random IV, we can't encrypt and match directly
|
// Since encryption uses random IV, we can't encrypt and match directly
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue