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

View File

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