fix: clear OTP inputs and reset focus on verification failure
This commit is contained in:
parent
b5c2d137e0
commit
de8873859e
1 changed files with 13 additions and 4 deletions
|
|
@ -218,17 +218,26 @@ export const OnboardingPage: React.FC = () => {
|
|||
}
|
||||
setStep1Loading(true);
|
||||
try {
|
||||
// Real-time backend OTP verification call
|
||||
// Real-time backend OTP verification call with strict validation
|
||||
const res = await api.verifyOtp('phone', enteredOtp);
|
||||
if (res && res.verified) {
|
||||
updateOnboarding({ isOtpVerified: true, phone: cleanPhone });
|
||||
handleNext();
|
||||
} else {
|
||||
setStep1Error(res?.error || 'Invalid OTP. Please try again.');
|
||||
setStep1Error(res?.error || 'Invalid or expired OTP code. Please enter the latest OTP received.');
|
||||
setStep1Otp(['', '', '', '', '', '']);
|
||||
setTimeout(() => {
|
||||
document.getElementById('step1-otp-0')?.focus();
|
||||
}, 300);
|
||||
}
|
||||
} catch (otpErr: any) {
|
||||
console.warn('OTP verification exception:', otpErr);
|
||||
setStep1Error(otpErr?.message || 'Invalid OTP. Please try again.');
|
||||
console.warn('Strict OTP verification failed:', otpErr);
|
||||
const msg = otpErr?.message || 'Invalid or expired OTP code. Please enter the latest OTP received.';
|
||||
setStep1Error(msg);
|
||||
setStep1Otp(['', '', '', '', '', '']);
|
||||
setTimeout(() => {
|
||||
document.getElementById('step1-otp-0')?.focus();
|
||||
}, 300);
|
||||
} finally {
|
||||
setStep1Loading(false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue