From 83ce76769aa161bdf47ae3722cb4d923c778210b Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 3 Oct 2026 16:26:42 +0530 Subject: [PATCH 1/6] fix(cart): display error for invalid or expired coupon codes (#4) --- src/App.tsx | 23 +++++++++++++--- src/components/cart/CartDrawer.tsx | 42 +++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c5ec65..a05a188 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -466,9 +466,18 @@ export default function App() { currency: currency }, { headers }); - setPricingCalc(res.data); - } catch (err) { + const calcData = res.data; + if (appliedCoupon && (!calcData.coupon_applied || calcData.coupon_applied === 'None')) { + calcData.coupon_error = calcData.coupon_error || 'Invalid or expired coupon code.'; + } + setPricingCalc(calcData); + } catch (err: any) { console.error('Pricing engine calculation error:', err); + const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.'; + setPricingCalc((prev: any) => ({ + ...(prev || {}), + coupon_error: errorMsg + })); } finally { setLoadingPricing(false); } @@ -525,6 +534,7 @@ export default function App() { const removePromoCode = () => { setAppliedCoupon(null); setCouponCode(''); + setPricingCalc((prev: any) => (prev ? { ...prev, coupon_error: null } : null)); }; const isModuleUnlocked = (code: string) => { @@ -574,10 +584,17 @@ export default function App() { setCheckoutLoading(true); setVerificationResult(null); + const isCouponValid = Boolean( + pricingCalc && + pricingCalc.coupon_applied && + pricingCalc.coupon_applied !== 'None' && + !pricingCalc.coupon_error + ); + try { const orderRes = await axios.post(`${API_BASE}/api/checkout/create-order`, { cart_item_codes: cart.map(item => item.code), - coupon_code: appliedCoupon || undefined, + coupon_code: isCouponValid ? appliedCoupon : undefined, currency: currency }, { headers: { 'Authorization': `Bearer ${userToken}` } diff --git a/src/components/cart/CartDrawer.tsx b/src/components/cart/CartDrawer.tsx index 5c49f3f..ec6398a 100644 --- a/src/components/cart/CartDrawer.tsx +++ b/src/components/cart/CartDrawer.tsx @@ -141,9 +141,11 @@ export const CartDrawer: React.FC = ({ {appliedCoupon && - (pricingCalc?.coupon_error ? ( + (pricingCalc?.coupon_error || !pricingCalc?.coupon_applied || pricingCalc?.coupon_applied === 'None' ? (
- ⚠️ {pricingCalc.coupon_error} + + ⚠️ {pricingCalc?.coupon_error || 'Invalid or expired coupon code.'} +
- {pricingCalc.total_discounts > 0 && ( + {pricingCalc.bundle_discount_amount > 0 && (
- Total Discounts + Bundle Discount -{currency === 'INR' - ? `₹${pricingCalc.total_discounts}` + ? `₹${pricingCalc.bundle_discount_amount}` : currency === 'EUR' - ? `€${pricingCalc.total_discounts}` - : `$${pricingCalc.total_discounts}`} + ? `€${pricingCalc.bundle_discount_amount}` + : `$${pricingCalc.bundle_discount_amount}`}
)} + {pricingCalc.coupon_discount_amount > 0 && ( +
+ Coupon Discount ({appliedCoupon}) + + -{currency === 'INR' + ? `₹${pricingCalc.coupon_discount_amount}` + : currency === 'EUR' + ? `€${pricingCalc.coupon_discount_amount}` + : `$${pricingCalc.coupon_discount_amount}`} + +
+ )} + {pricingCalc.total_discounts > 0 && + !pricingCalc.bundle_discount_amount && + !pricingCalc.coupon_discount_amount && ( +
+ Total Discounts + + -{currency === 'INR' + ? `₹${pricingCalc.total_discounts}` + : currency === 'EUR' + ? `€${pricingCalc.total_discounts}` + : `$${pricingCalc.total_discounts}`} + +
+ )} {pricingCalc.convenience_fee > 0 && (
Gateway fee ({pricingCalc.convenience_fee_rate}%) From 4f2e83228304f629388a96139612d0e2bc157039 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 3 Oct 2026 17:25:48 +0530 Subject: [PATCH 2/6] fix(checkout): ensure "Open in App" button reliably launches mobile app (#7) --- src/App.tsx | 11 +++- .../checkout/PaymentSuccessModal.tsx | 53 +++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c5ec65..1cbc898 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -658,9 +658,18 @@ export default function App() { message: verifyRes.data.message || 'Payment verified successfully and module entitlements unlocked!' }); + // If on mobile browser, automatically attempt to redirect to mobile app after successful payment if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) { setTimeout(() => { - window.location.href = 'acupedia://'; + if (/Android/i.test(navigator.userAgent)) { + // Use Android Intent format to avoid blocked navigation in Android Chrome + window.location.href = 'intent://#Intent;scheme=acupedia;package=com.anonymous.acupedia;end'; + setTimeout(() => { + window.location.href = 'acupedia://'; + }, 500); + } else { + window.location.href = 'acupedia://'; + } }, 1500); } diff --git a/src/components/checkout/PaymentSuccessModal.tsx b/src/components/checkout/PaymentSuccessModal.tsx index f665a26..234bbfe 100644 --- a/src/components/checkout/PaymentSuccessModal.tsx +++ b/src/components/checkout/PaymentSuccessModal.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react'; import type { VerificationResult, UserProfile } from '../../types'; @@ -17,6 +17,42 @@ export const PaymentSuccessModal: React.FC = ({ onDownloadInvoice, downloadingInvoice, }) => { + const [desktopNotice, setDesktopNotice] = useState(false); + + // Handler to reliably launch the Acupedia Mobile App across platforms (Android, iOS, and Desktop) + const handleOpenApp = (e: React.MouseEvent) => { + e.preventDefault(); + const userAgent = navigator.userAgent || ''; + const isAndroid = /Android/i.test(userAgent); + const isIOS = /iPhone|iPad|iPod/i.test(userAgent); + + if (isAndroid) { + // Android Chrome requires an Intent URI format to launch apps by package and scheme reliably + const intentUrl = 'intent://#Intent;scheme=acupedia;package=com.anonymous.acupedia;end'; + window.location.href = intentUrl; + + // Fallback to custom URI schemes in case intent fails or Expo uses alternate scheme + setTimeout(() => { + window.location.href = 'acupedia://'; + }, 500); + setTimeout(() => { + window.location.href = 'myapp://'; + }, 1000); + } else if (isIOS) { + // iOS Safari and Chrome handle custom URI schemes directly + window.location.href = 'acupedia://'; + + // Fallback in case Expo uses default 'myapp://' scheme + setTimeout(() => { + window.location.href = 'myapp://'; + }, 500); + } else { + // On desktop browsers, try opening the registered custom scheme + window.location.href = 'acupedia://'; + // Show helpful desktop feedback informing the user how to access content on mobile + setDesktopNotice(true); + } + }; return (
@@ -175,14 +211,25 @@ export const PaymentSuccessModal: React.FC = ({ )} + {/* Open in App Button */} - Open Acupedia Mobile App + Open in App + {desktopNotice && ( +
+

+ 📱 Attempted to launch Acupedia App. If you are on desktop, please open the Acupedia App on your mobile device to view your unlocked content. +

+
+ )} +
)} @@ -320,7 +337,14 @@ export const AuthModal: React.FC = ({
setProfilePhone(e.target.value)} + onChange={(e) => setProfilePhone(cleanPhoneInput(e.target.value))} placeholder="+919876543210" + maxLength={18} className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500" />
diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 55fdde1..d2791de 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -2,22 +2,61 @@ export interface CountryCode { code: string; label: string; country: string; + minLength: number; + maxLength: number; + placeholder: string; } export const COUNTRY_CODES: CountryCode[] = [ - { code: '+91', label: '🇮🇳 +91', country: 'India' }, - { code: '+1', label: '🇺🇸 +1', country: 'US' }, - { code: '+44', label: '🇬🇧 +44', country: 'UK' }, - { code: '+61', label: '🇦🇺 +61', country: 'AU' }, - { code: '+49', label: '🇩🇪 +49', country: 'DE' }, - { code: '+33', label: '🇫🇷 +33', country: 'FR' }, - { code: '+81', label: '🇯🇵 +81', country: 'JP' }, - { code: '+86', label: '🇨🇳 +86', country: 'CN' }, - { code: '+971', label: '🇦🇪 +971', country: 'UAE' }, - { code: '+65', label: '🇸🇬 +65', country: 'SG' }, - { code: '+55', label: '🇧🇷 +55', country: 'BR' }, - { code: '+82', label: '🇰🇷 +82', country: 'KR' }, - { code: '+7', label: '🇷🇺 +7', country: 'RU' }, - { code: '+27', label: '🇿🇦 +27', country: 'ZA' }, - { code: '+234', label: '🇳🇬 +234', country: 'NG' }, + { code: '+91', label: '🇮🇳 +91', country: 'India', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { code: '+1', label: '🇺🇸 +1', country: 'United States', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, + { code: '+44', label: '🇬🇧 +44', country: 'United Kingdom', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+61', label: '🇦🇺 +61', country: 'Australia', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { code: '+49', label: '🇩🇪 +49', country: 'Germany', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+33', label: '🇫🇷 +33', country: 'France', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { code: '+81', label: '🇯🇵 +81', country: 'Japan', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+86', label: '🇨🇳 +86', country: 'China', minLength: 11, maxLength: 11, placeholder: '11-digit mobile number' }, + { code: '+971', label: '🇦🇪 +971', country: 'UAE', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { code: '+65', label: '🇸🇬 +65', country: 'Singapore', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { code: '+55', label: '🇧🇷 +55', country: 'Brazil', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+82', label: '🇰🇷 +82', country: 'South Korea', minLength: 9, maxLength: 11, placeholder: '9 to 11 digits' }, + { code: '+7', label: '🇷🇺 +7', country: 'Russia', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { code: '+27', label: '🇿🇦 +27', country: 'South Africa', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { code: '+234', label: '🇳🇬 +234', country: 'Nigeria', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, ]; + +export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { + return ( + COUNTRY_CODES.find((c) => c.code === dialCode) || { + code: dialCode, + label: dialCode, + country: 'Other', + minLength: 6, + maxLength: 15, + placeholder: 'Phone number', + } + ); +}; + +export const getCountryRuleByName = (countryName: string): CountryCode => { + if (!countryName) return COUNTRY_CODES[0]; + const normalized = countryName.toLowerCase(); + return ( + COUNTRY_CODES.find( + (c) => + c.country.toLowerCase() === normalized || + (normalized.includes('india') && c.country === 'India') || + (normalized.includes('united states') && c.country === 'United States') || + (normalized.includes('united kingdom') && c.country === 'United Kingdom') || + (normalized.includes('germany') && c.country === 'Germany') || + (normalized.includes('australia') && c.country === 'Australia') + ) || { + code: '+91', + label: '🇮🇳 +91', + country: countryName, + minLength: 6, + maxLength: 15, + placeholder: 'Phone number', + } + ); +}; diff --git a/src/utils/validation.ts b/src/utils/validation.ts new file mode 100644 index 0000000..60b58ac --- /dev/null +++ b/src/utils/validation.ts @@ -0,0 +1,76 @@ +import { getCountryRuleByDialCode, getCountryRuleByName } from '../constants/countries'; + +/** + * Strips non-numeric / non-phone characters from text in real-time + * If maxLength is provided, strictly restricts digit length + */ +export const cleanPhoneInput = (text: string, maxLength?: number): string => { + const trimmedStart = text.trimStart(); + const hasPlus = trimmedStart.startsWith('+'); + const rest = hasPlus ? trimmedStart.slice(1) : text; + const digitsOnly = rest.replace(/\D/g, ''); + const boundedDigits = maxLength ? digitsOnly.slice(0, maxLength) : digitsOnly; + return hasPlus ? `+${boundedDigits}` : boundedDigits; +}; + +/** + * Validates phone number according to country rules (e.g. India = exactly 10 digits) + */ +export const validatePhoneNumber = ( + val?: string | null, + dialCode?: string, + country?: string +): string | null => { + if (!val || !val.trim()) return null; + const trimmed = val.trim(); + const digits = trimmed.replace(/\D/g, ''); + + if (digits.length === 0) { + return 'Please enter a valid phone number with numeric digits.'; + } + + // Resolve country rule by dial code or country name + let rule = dialCode ? getCountryRuleByDialCode(dialCode) : undefined; + if ((!rule || rule.country === 'Other') && country) { + rule = getCountryRuleByName(country); + } + // Default to India if no specific rule resolved and dial code is +91 or country is India + if (!rule || rule.country === 'Other') { + if (dialCode === '+91' || (country && country.toLowerCase() === 'india')) { + rule = getCountryRuleByDialCode('+91'); + } + } + + if (rule && rule.country !== 'Other') { + if (rule.minLength === rule.maxLength) { + if (digits.length !== rule.minLength) { + return `${rule.country} phone number must be exactly ${rule.minLength} digits.`; + } + } else { + if (digits.length < rule.minLength) { + return `${rule.country} phone number must be at least ${rule.minLength} digits.`; + } + if (digits.length > rule.maxLength) { + return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`; + } + } + return null; + } + + // General fallback ITU E.164 + if (digits.length < 6) { + return 'Phone number must contain at least 6 digits.'; + } + if (digits.length > 15) { + return 'Phone number cannot exceed 15 digits.'; + } + return null; +}; + +export const isValidPhoneNumber = ( + val?: string | null, + dialCode?: string, + country?: string +): boolean => { + return validatePhoneNumber(val, dialCode, country) === null; +}; From b476492bd8db1c1074a27b4dfe795ef022156dbc Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Mon, 5 Oct 2026 13:56:41 +0530 Subject: [PATCH 5/6] refactor(auth): make country and phone code configuration generic across store - Render country selection options dynamically from COUNTRY_CODES in AuthModal and ProfileDrawer - Synchronize dial code, country, and currency generically using getCountryRuleByName and getCountryRuleByDialCode - Eliminate hardcoded country options and country-specific checks in favor of registry-driven rules --- src/App.tsx | 22 +++++---------- src/components/auth/AuthModal.tsx | 32 +++++++++++----------- src/components/auth/ProfileDrawer.tsx | 38 +++++++++++++------------- src/constants/countries.ts | 39 ++++++++++++++++----------- 4 files changed, 63 insertions(+), 68 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 15deeb4..150d6c9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import axios from 'axios'; import { CURRICULUM_MODULES } from './constants/modules'; -import { COUNTRY_CODES } from './constants/countries'; +import { getCountryRuleByName } from './constants/countries'; import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types'; import { API_BASE } from './services/api'; import { loadRazorpayScript } from './services/razorpay'; @@ -216,16 +216,9 @@ export default function App() { // Update currency and dial code automatically on country selection during registration useEffect(() => { if (authMode === 'register') { - if (authCountry === 'India') { - setCurrency('INR'); - setAuthDialCode('+91'); - } else { - setCurrency('USD'); - const match = COUNTRY_CODES.find(c => c.country.toLowerCase() === authCountry.toLowerCase()); - if (match) { - setAuthDialCode(match.code); - } - } + const rule = getCountryRuleByName(authCountry); + setCurrency(rule.currency); + setAuthDialCode(rule.code); } }, [authCountry, authMode]); @@ -247,11 +240,8 @@ export default function App() { setProfileDisplayName(profileRes.data.display_name || ''); setProfilePhone(profileRes.data.phone_number || ''); setProfileCountry(profileRes.data.country || 'India'); - if (profileRes.data.country === 'India') { - setCurrency('INR'); - } else { - setCurrency('USD'); - } + const countryRule = getCountryRuleByName(profileRes.data.country || 'India'); + setCurrency(countryRule.currency); } catch (err) { console.error('Failed to fetch user profile:', err); handleLogout(); diff --git a/src/components/auth/AuthModal.tsx b/src/components/auth/AuthModal.tsx index 60d4231..8f09273 100644 --- a/src/components/auth/AuthModal.tsx +++ b/src/components/auth/AuthModal.tsx @@ -3,7 +3,7 @@ import { XCircle, Sparkles, AlertCircle, CheckCircle, RefreshCw, Phone, Globe, Eye, EyeOff, LogIn, UserPlus } from 'lucide-react'; -import { COUNTRY_CODES, getCountryRuleByDialCode } from '../../constants/countries'; +import { COUNTRY_CODES, getCountryRuleByDialCode, getCountryRuleByName } from '../../constants/countries'; import { cleanPhoneInput } from '../../utils/validation'; interface AuthModalProps { @@ -295,9 +295,9 @@ export const AuthModal: React.FC = ({ onChange={(e) => { const newCode = e.target.value; setAuthDialCode(newCode); - const match = COUNTRY_CODES.find((c) => c.code === newCode); - if (match && match.country) { - setAuthCountry(match.country); + const rule = getCountryRuleByDialCode(newCode); + if (rule && rule.country !== 'Other') { + setAuthCountry(rule.country); } }} className="w-[90px] bg-slate-950 border border-slate-800 rounded-xl px-3 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 appearance-none" @@ -319,11 +319,9 @@ export const AuthModal: React.FC = ({ />

- {activeRule.country === 'India' - ? '🇮🇳 India: Enter 10-digit mobile number' - : activeRule.minLength === activeRule.maxLength - ? `${activeRule.country}: Requires exactly ${activeRule.maxLength} digits` - : `${activeRule.country}: ${activeRule.minLength} to ${activeRule.maxLength} digits`} + {activeRule.minLength === activeRule.maxLength + ? `${activeRule.label || activeRule.country}: Requires exactly ${activeRule.maxLength} digits` + : `${activeRule.label || activeRule.country}: ${activeRule.minLength} to ${activeRule.maxLength} digits`}

)} @@ -340,18 +338,18 @@ export const AuthModal: React.FC = ({ onChange={(e) => { const newCountry = e.target.value; setAuthCountry(newCountry); - const match = COUNTRY_CODES.find((c) => c.country.toLowerCase() === newCountry.toLowerCase()); - if (match) { - setAuthDialCode(match.code); + const rule = getCountryRuleByName(newCountry); + if (rule) { + setAuthDialCode(rule.code); } }} className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 appearance-none" > - - - - - + {COUNTRY_CODES.map((cc) => ( + + ))}
▼ diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index bcb992f..437199e 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -4,6 +4,7 @@ import { Eye, EyeOff, RefreshCw, LogOut } from 'lucide-react'; import type { UserProfile, ModuleItem, Currency } from '../../types'; +import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; import { cleanPhoneInput } from '../../utils/validation'; interface ProfileDrawerProps { @@ -71,6 +72,7 @@ export const ProfileDrawer: React.FC = ({ }) => { const [showOldPassword, setShowOldPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false); + const activeRule = getCountryRuleByName(profileCountry); if (!isOpen || !loggedInUser) return null; @@ -144,11 +146,16 @@ export const ProfileDrawer: React.FC = ({ setProfilePhone(cleanPhoneInput(e.target.value))} - placeholder="+919876543210" - maxLength={18} + onChange={(e) => setProfilePhone(cleanPhoneInput(e.target.value, activeRule.maxLength))} + placeholder={activeRule.placeholder} + maxLength={activeRule.maxLength} className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500" /> +

+ {activeRule.minLength === activeRule.maxLength + ? `${activeRule.label || activeRule.country}: Requires exactly ${activeRule.maxLength} digits` + : `${activeRule.label || activeRule.country}: ${activeRule.minLength} to ${activeRule.maxLength} digits`} +

@@ -156,25 +163,18 @@ export const ProfileDrawer: React.FC = ({
diff --git a/src/constants/countries.ts b/src/constants/countries.ts index d2791de..f3ab5d4 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -1,36 +1,42 @@ +import type { Currency } from '../types'; + export interface CountryCode { code: string; label: string; country: string; + currency: Currency; minLength: number; maxLength: number; placeholder: string; } export const COUNTRY_CODES: CountryCode[] = [ - { code: '+91', label: '🇮🇳 +91', country: 'India', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+1', label: '🇺🇸 +1', country: 'United States', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, - { code: '+44', label: '🇬🇧 +44', country: 'United Kingdom', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+61', label: '🇦🇺 +61', country: 'Australia', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+49', label: '🇩🇪 +49', country: 'Germany', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+33', label: '🇫🇷 +33', country: 'France', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+81', label: '🇯🇵 +81', country: 'Japan', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+86', label: '🇨🇳 +86', country: 'China', minLength: 11, maxLength: 11, placeholder: '11-digit mobile number' }, - { code: '+971', label: '🇦🇪 +971', country: 'UAE', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+65', label: '🇸🇬 +65', country: 'Singapore', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+55', label: '🇧🇷 +55', country: 'Brazil', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+82', label: '🇰🇷 +82', country: 'South Korea', minLength: 9, maxLength: 11, placeholder: '9 to 11 digits' }, - { code: '+7', label: '🇷🇺 +7', country: 'Russia', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+27', label: '🇿🇦 +27', country: 'South Africa', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+234', label: '🇳🇬 +234', country: 'Nigeria', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+91', label: '🇮🇳 +91', country: 'India', currency: 'INR', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { code: '+1', label: '🇺🇸 +1', country: 'United States', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, + { code: '+44', label: '🇬🇧 +44', country: 'United Kingdom', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+61', label: '🇦🇺 +61', country: 'Australia', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { code: '+49', label: '🇩🇪 +49', country: 'Germany', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+33', label: '🇫🇷 +33', country: 'France', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { code: '+81', label: '🇯🇵 +81', country: 'Japan', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+86', label: '🇨🇳 +86', country: 'China', currency: 'USD', minLength: 11, maxLength: 11, placeholder: '11-digit mobile number' }, + { code: '+971', label: '🇦🇪 +971', country: 'UAE', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { code: '+65', label: '🇸🇬 +65', country: 'Singapore', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { code: '+55', label: '🇧🇷 +55', country: 'Brazil', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { code: '+82', label: '🇰🇷 +82', country: 'South Korea', currency: 'USD', minLength: 9, maxLength: 11, placeholder: '9 to 11 digits' }, + { code: '+7', label: '🇷🇺 +7', country: 'Russia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { code: '+27', label: '🇿🇦 +27', country: 'South Africa', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { code: '+234', label: '🇳🇬 +234', country: 'Nigeria', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, ]; +export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91) + export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { return ( COUNTRY_CODES.find((c) => c.code === dialCode) || { code: dialCode, label: dialCode, country: 'Other', + currency: 'USD', minLength: 6, maxLength: 15, placeholder: 'Phone number', @@ -39,7 +45,7 @@ export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { }; export const getCountryRuleByName = (countryName: string): CountryCode => { - if (!countryName) return COUNTRY_CODES[0]; + if (!countryName) return DEFAULT_COUNTRY; const normalized = countryName.toLowerCase(); return ( COUNTRY_CODES.find( @@ -54,6 +60,7 @@ export const getCountryRuleByName = (countryName: string): CountryCode => { code: '+91', label: '🇮🇳 +91', country: countryName, + currency: normalized === 'india' ? 'INR' : 'USD', minLength: 6, maxLength: 15, placeholder: 'Phone number', From f3d13722e3c8310662b061153165d20396810e5a Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Mon, 5 Oct 2026 17:26:54 +0530 Subject: [PATCH 6/6] fix(auth): enforce password special character validation and disallow whitespace as special character --- src/App.tsx | 28 +++++++++++++++++++++++++-- src/components/auth/ProfileDrawer.tsx | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c5ec65..a9e3488 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -299,6 +299,30 @@ export default function App() { setAuthError(null); const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register'; + + if (authMode === 'register') { + if (authPassword.length < 8) { + setAuthError('Password must be at least 8 characters long.'); + setAuthLoading(false); + return; + } + if (!/[A-Z]/.test(authPassword)) { + setAuthError('Password must contain at least one uppercase letter.'); + setAuthLoading(false); + return; + } + if (!/[0-9]/.test(authPassword)) { + setAuthError('Password must contain at least one number.'); + setAuthLoading(false); + return; + } + if (!/[^A-Za-z0-9\s]/.test(authPassword)) { + setAuthError('Password must contain at least one special character.'); + setAuthLoading(false); + return; + } + } + const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined; const payload = authMode === 'login' ? { email: authEmail, password: authPassword } @@ -352,7 +376,7 @@ export default function App() { setChangePasswordError('New password must contain at least one number.'); return; } - if (!/[^A-Za-z0-9]/.test(changeNewPassword)) { + if (!/[^A-Za-z0-9\s]/.test(changeNewPassword)) { setChangePasswordError('New password must contain at least one special character.'); return; } @@ -423,7 +447,7 @@ export default function App() { setAuthLoading(false); return; } - if (!/[^A-Za-z0-9]/.test(resetNewPassword)) { + if (!/[^A-Za-z0-9\s]/.test(resetNewPassword)) { setAuthError('New password must contain at least one special character.'); setAuthLoading(false); return; diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index 47f2754..2b0c22e 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -285,7 +285,7 @@ export const ProfileDrawer: React.FC = ({ • 1 number - + • 1 special char