From 41bbc2ca6fba4f4cbe09939b60e3ce21a9dc0f9d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Jan 2026 14:17:40 +0530 Subject: [PATCH] Email signin verification code changes --- app/controllers/establishment.controller.js | 32 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index 6d8355c..0f24d75 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -1054,6 +1054,31 @@ exports.forgotPasswordVerifyOTP = async (req, res) => { return res.status(500).json({ status: "failed", message: "Internal server error" }); } }; +function formatUAEPhoneNumber(phone) { + if (!phone) return ''; + + // Convert number → string safely + let digits = String(phone).replace(/\D/g, ''); + + // Case 1: 9-digit UAE mobile (e.g. 506491429) + if (digits.length === 9 && digits.startsWith('5')) { + digits = '971' + digits; + } + + // Case 2: 10-digit starting with 0 (e.g. 0506491429) + if (digits.length === 10 && digits.startsWith('0')) { + digits = '971' + digits.substring(1); + } + + // Case 3: Already has country code + if (digits.startsWith('971') && digits.length === 12) { + // ok + } else if (!digits.startsWith('971')) { + return phone; // fail-safe + } + + return `+${digits.substring(0, 3)} ${digits.substring(3, 5)} ${digits.substring(5, 8)} ${digits.substring(8)}`; +} exports.requestOTPForLogin = async (req, res) => { try { @@ -1103,13 +1128,14 @@ exports.requestOTPForLogin = async (req, res) => { { where: { email: registered_email } } - ); + ); + const formattedSupportPhone = formatUAEPhoneNumber(process.env.SUPPORT_PHONE); const placeHolderData = { username: loggingUser.name, verfication_code: otp, - otp_expiry: otp_expiry, + otp_expiry: 10, support_email: process.env.SUPPORT_EMAIL, - support_phone: process.env.SUPPORT_PHONE, + support_phone: formattedSupportPhone, logo_url: `${process.env.APP_BASE_URL}/assets/FCSCLogo.png` };