fix(otp): support WebOTP sms pattern with {0} and {1} and robust code extraction
Deploy Canina / deploy (push) Successful in 3m53s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 0s

This commit is contained in:
parsa aghaei committed 2026-09-05 19:36:49 +03:30
1 parent 1fd9a92dd0
commit c57f775cb4
15 files changed
+8628 -8534

No files matched your search

@@ -216,9 +216,9 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
signal: ac.signal,
}).then((otp) => {
if (!isMounted || !otp) return;
// OTPCredential.code is the extracted code, not the full SMS text.
// Still run toEnglishDigits in case it contains Persian numerals.
const digits = toEnglishDigits(otp.code ?? "").replace(/[^0-9]/g, "").slice(0, 5);
// OTPCredential.code is the extracted code, but fallback to any string property
const rawCode = (otp as { code?: string })?.code || (otp as { id?: string })?.id || "";
const digits = extractOtpFromText(rawCode);
if (digits.length === 5) {
setOtpCode(digits);
// 400 ms delay so the user can see the filled boxes before verification
+11 -2
View File
@@ -5,10 +5,18 @@ import { X, ShieldCheck, Phone, Key, LogIn, ArrowRight, RefreshCw } from "lucide
import { authService } from "../lib/services/authService";
import { useUserStore } from "../lib/store/userStore";
import { toast } from "sonner";
import { toPersian } from "../lib/utils";
import { toPersian, toEnglishDigits } from "../lib/utils";
import OtpInput5 from "./OtpInput5";
function extractOtpFromText(text: string): string {
if (!text) return "";
const clean = toEnglishDigits(text);
const match = clean.match(/(\d{5})/);
if (match) return match[1];
return clean.replace(/[^0-9]/g, "").slice(0, 5);
}
interface LoginModalProps {
isOpen: boolean;
onClose: () => void;
@@ -115,7 +123,8 @@ export default function LoginModal({ isOpen, onClose, onLogin, petName, isAdviso
signal: ac.signal,
}).then((otp) => {
if (!isMounted || !otp) return;
const digits = otp.code?.replace(/[^0-9]/g, "").slice(0, 5) ?? "";
const rawCode = (otp as { code?: string })?.code || (otp as { id?: string })?.id || "";
const digits = extractOtpFromText(rawCode);
if (digits.length === 5) {
setOtpCode(digits);
setTimeout(() => {