chore: add phone number logic changed

This commit is contained in:
مهرزاد قدرتی
2025-08-12 11:52:09 +03:30
parent b8f7221780
commit e4755ded73
3 changed files with 28 additions and 41 deletions

View File

@@ -69,6 +69,16 @@ export const AuthenticationSteps = (): JSX.Element => {
location.href = authReturnUrl;
};
const handleConfrimPhoneNumber = (userId: GUID) => {
handleUserLoggedIn(userId);
setCurrentStep('addPhoneNumber');
};
const handlePhoneNumberVerified = () => {
location.href = authReturnUrl;
};
return (
<>
{currentStep === 'emailOrPhone' && (
@@ -87,7 +97,7 @@ export const AuthenticationSteps = (): JSX.Element => {
{currentStep === 'verify' && (
<OtpVerifyForm
onVerifyPhoneNumber={() => setCurrentStep('addPhoneNumber')}
onVerifyPhoneNumber={handleConfrimPhoneNumber}
authReturnUrl={authReturnUrl}
countryCode={countryCode}
onOTPVerified={handleOTPVerfied}
@@ -129,7 +139,7 @@ export const AuthenticationSteps = (): JSX.Element => {
onEditValue={() => setCurrentStep('addPhoneNumber')}
value={addedPhoneNumberValue}
email={loginRegisterValue}
onPhoneNumberVerified={handleUserLoggedIn}
onPhoneNumberVerified={handlePhoneNumberVerified}
/>
)}
</>

View File

@@ -25,8 +25,8 @@ interface OtpVerifyFormProps {
authType: AuthType;
authMode: AuthMode;
onEditValue: () => void;
onOTPVerified: (userID: GUID) => void;
onVerifyPhoneNumber: () => void;
onOTPVerified: (userId: GUID) => void;
onVerifyPhoneNumber: (userId: GUID) => void;
authReturnUrl: string;
}
@@ -95,38 +95,11 @@ export function OtpVerifyForm({
if (!otpCode || otpCode.length < 4) {
setOtpDigitInvalid(true);
} else {
if (authMode === 'register' && authType === 'email') {
handleConfirmEmailAndAddPhone();
} else {
handleLoginRequestWithOtp();
}
handleLoginOrSignUp();
}
};
const handleConfirmEmailAndAddPhone = async () => {
setOtpDigitInvalid(false);
setVerifyStatusLoading(true);
const confirmOtpRequest: ConfirmEmailOtpRequest = {
otpCode: otpCode,
email: value,
};
const result = await confirmEmailOtp(confirmOtpRequest);
const jsonRes = await result.json();
if (jsonRes.success) {
setVerifyStatus('success');
onVerifyPhoneNumber();
} else {
setVerifyStatus('failed');
setErrorMessage(jsonRes.message);
}
setVerifyAlertOpen(true);
setVerifyStatusLoading(false);
};
const handleLoginRequestWithOtp = async () => {
const handleLoginOrSignUp = async () => {
setOtpDigitInvalid(false);
setVerifyStatusLoading(true);
@@ -141,7 +114,12 @@ export function OtpVerifyForm({
if (jsonRes.success) {
setVerifyStatus('success');
onOTPVerified(jsonRes.userId);
if (jsonRes.registeredWithOutPhoneNumber) {
onVerifyPhoneNumber(jsonRes.userId);
} else {
onOTPVerified(jsonRes.userId);
}
} else {
setVerifyStatus('failed');
setErrorMessage(jsonRes.message);

View File

@@ -6,9 +6,10 @@ import type { AuthMode, AuthType } from '../../types/authTypes';
import { useEffect, useState } from 'react';
import { Toast } from '@/components/Toast';
import { AuthenticationCard } from '../AuthenticationCard';
import type { LoginRequest } from '../../types/userTypes';
import type { ConfirmSmsOtpRequest, LoginRequest } from '../../types/userTypes';
import { useSearchParams } from 'react-router';
import {
confirmSmsOtp,
loginOrSignUpWithOtp,
sendEmailOtp,
sendSmsOtp,
@@ -21,7 +22,7 @@ interface VerifyPhoneNumberProps {
email: string;
countryCode: CountryCode;
onEditValue: () => void;
onPhoneNumberVerified: (userId: GUID) => void;
onPhoneNumberVerified: () => void;
}
export function VerifyPhoneNumber({
@@ -86,18 +87,16 @@ export function VerifyPhoneNumber({
setOtpDigitInvalid(false);
setVerifyStatusLoading(true);
const loginRequest: LoginRequest = {
const confirmSmsOtpRequest: ConfirmSmsOtpRequest = {
otpCode: otpCode,
phoneNumber: countryCode + value,
email: email,
returnUrl: authReturnUrl,
};
const result = await loginOrSignUpWithOtp(loginRequest);
const result = await confirmSmsOtp(confirmSmsOtpRequest);
const jsonRes = await result.json();
if (jsonRes.success) {
setVerifyStatus('success');
onPhoneNumberVerified(jsonRes.userId);
onPhoneNumberVerified();
} else {
setVerifyStatus('failed');
setErrorMessage(jsonRes.message);