fix(auth): resolve phone number detection when value contains + prefix

This commit is contained in:
2026-06-13 10:22:40 +03:30
parent f5aa159020
commit 96e19fc736
2 changed files with 17 additions and 8 deletions

View File

@@ -7,7 +7,6 @@ import type {
AuthType, AuthType,
} from '../../types/authTypes'; } from '../../types/authTypes';
import { OtpVerifyForm } from './OtpVerifyForm'; import { OtpVerifyForm } from './OtpVerifyForm';
import { isNumeric } from '@/utils/regexes/isNumeric';
import { CompleteSignUp } from './CompleteSignUp'; import { CompleteSignUp } from './CompleteSignUp';
import { EnterPasswordForm } from './EnterPasswordForm'; import { EnterPasswordForm } from './EnterPasswordForm';
import { UserStatus, type LoginResult } from '../../types/userTypes'; import { UserStatus, type LoginResult } from '../../types/userTypes';
@@ -68,11 +67,12 @@ export const AuthenticationSteps = (): JSX.Element => {
}, [searchParams]); }, [searchParams]);
const handleLoginRegister = ( const handleLoginRegister = (
value: string, _: string,
userStatus: UserStatus, userStatus: UserStatus,
timerValue: number, timerValue: number,
authType: AuthType,
) => { ) => {
setAuthType(isNumeric(value) ? 'phone' : 'email'); setAuthType(authType);
setTimerValue(timerValue); setTimerValue(timerValue);
switch (userStatus) { switch (userStatus) {

View File

@@ -28,6 +28,7 @@ export interface LoginRegisterFormProps {
value: string, value: string,
userStatus: UserStatus, userStatus: UserStatus,
timerValue: number, timerValue: number,
authType: AuthType,
) => void; ) => void;
onGoogleAuthenticated: ( onGoogleAuthenticated: (
loginResult: LoginResult, loginResult: LoginResult,
@@ -75,8 +76,8 @@ export function LoginRegisterForm({
setLoginRegisterValue(newValue); setLoginRegisterValue(newValue);
// If the new value contains only digits (or is empty), it's a phone number const strippedValue = newValue.startsWith('+') ? newValue.substring(1) : newValue;
if (isNumeric(newValue)) { if (isNumeric(strippedValue) && strippedValue.length > 0) {
setAuthType('phone'); setAuthType('phone');
} else { } else {
setAuthType('email'); setAuthType('email');
@@ -103,9 +104,16 @@ export function LoginRegisterForm({
return false; return false;
} }
if (authType === 'phone' && !isPhoneNumber(countryCode, value)) { if (authType === 'phone') {
if (setErrors) setError('loginForm.phoneNumberIsInvalid'); // Strip leading + for validation if country code already selected
return false; const normalizedValue = value.startsWith('+')
? value.substring(1)
: value;
if (!isPhoneNumber(countryCode, normalizedValue)) {
if (setErrors) setError('loginForm.phoneNumberIsInvalid');
return false;
}
} }
if (setErrors) setError(undefined); if (setErrors) setError(undefined);
@@ -139,6 +147,7 @@ export function LoginRegisterForm({
newValue, newValue,
res.userStatus, res.userStatus,
res.totalSecondForOtpToExpire, res.totalSecondForOtpToExpire,
authType
); );
} else { } else {
toast({ message: res.message, severity: 'error' }); toast({ message: res.message, severity: 'error' });