chore: add phone number logic changed
This commit is contained in:
@@ -69,6 +69,16 @@ export const AuthenticationSteps = (): JSX.Element => {
|
|||||||
location.href = authReturnUrl;
|
location.href = authReturnUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleConfrimPhoneNumber = (userId: GUID) => {
|
||||||
|
handleUserLoggedIn(userId);
|
||||||
|
|
||||||
|
setCurrentStep('addPhoneNumber');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePhoneNumberVerified = () => {
|
||||||
|
location.href = authReturnUrl;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{currentStep === 'emailOrPhone' && (
|
{currentStep === 'emailOrPhone' && (
|
||||||
@@ -87,7 +97,7 @@ export const AuthenticationSteps = (): JSX.Element => {
|
|||||||
|
|
||||||
{currentStep === 'verify' && (
|
{currentStep === 'verify' && (
|
||||||
<OtpVerifyForm
|
<OtpVerifyForm
|
||||||
onVerifyPhoneNumber={() => setCurrentStep('addPhoneNumber')}
|
onVerifyPhoneNumber={handleConfrimPhoneNumber}
|
||||||
authReturnUrl={authReturnUrl}
|
authReturnUrl={authReturnUrl}
|
||||||
countryCode={countryCode}
|
countryCode={countryCode}
|
||||||
onOTPVerified={handleOTPVerfied}
|
onOTPVerified={handleOTPVerfied}
|
||||||
@@ -129,7 +139,7 @@ export const AuthenticationSteps = (): JSX.Element => {
|
|||||||
onEditValue={() => setCurrentStep('addPhoneNumber')}
|
onEditValue={() => setCurrentStep('addPhoneNumber')}
|
||||||
value={addedPhoneNumberValue}
|
value={addedPhoneNumberValue}
|
||||||
email={loginRegisterValue}
|
email={loginRegisterValue}
|
||||||
onPhoneNumberVerified={handleUserLoggedIn}
|
onPhoneNumberVerified={handlePhoneNumberVerified}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ interface OtpVerifyFormProps {
|
|||||||
authType: AuthType;
|
authType: AuthType;
|
||||||
authMode: AuthMode;
|
authMode: AuthMode;
|
||||||
onEditValue: () => void;
|
onEditValue: () => void;
|
||||||
onOTPVerified: (userID: GUID) => void;
|
onOTPVerified: (userId: GUID) => void;
|
||||||
onVerifyPhoneNumber: () => void;
|
onVerifyPhoneNumber: (userId: GUID) => void;
|
||||||
authReturnUrl: string;
|
authReturnUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,38 +95,11 @@ export function OtpVerifyForm({
|
|||||||
if (!otpCode || otpCode.length < 4) {
|
if (!otpCode || otpCode.length < 4) {
|
||||||
setOtpDigitInvalid(true);
|
setOtpDigitInvalid(true);
|
||||||
} else {
|
} else {
|
||||||
if (authMode === 'register' && authType === 'email') {
|
handleLoginOrSignUp();
|
||||||
handleConfirmEmailAndAddPhone();
|
|
||||||
} else {
|
|
||||||
handleLoginRequestWithOtp();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmEmailAndAddPhone = async () => {
|
const handleLoginOrSignUp = 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 () => {
|
|
||||||
setOtpDigitInvalid(false);
|
setOtpDigitInvalid(false);
|
||||||
setVerifyStatusLoading(true);
|
setVerifyStatusLoading(true);
|
||||||
|
|
||||||
@@ -141,7 +114,12 @@ export function OtpVerifyForm({
|
|||||||
|
|
||||||
if (jsonRes.success) {
|
if (jsonRes.success) {
|
||||||
setVerifyStatus('success');
|
setVerifyStatus('success');
|
||||||
onOTPVerified(jsonRes.userId);
|
|
||||||
|
if (jsonRes.registeredWithOutPhoneNumber) {
|
||||||
|
onVerifyPhoneNumber(jsonRes.userId);
|
||||||
|
} else {
|
||||||
|
onOTPVerified(jsonRes.userId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setVerifyStatus('failed');
|
setVerifyStatus('failed');
|
||||||
setErrorMessage(jsonRes.message);
|
setErrorMessage(jsonRes.message);
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import type { AuthMode, AuthType } from '../../types/authTypes';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Toast } from '@/components/Toast';
|
import { Toast } from '@/components/Toast';
|
||||||
import { AuthenticationCard } from '../AuthenticationCard';
|
import { AuthenticationCard } from '../AuthenticationCard';
|
||||||
import type { LoginRequest } from '../../types/userTypes';
|
import type { ConfirmSmsOtpRequest, LoginRequest } from '../../types/userTypes';
|
||||||
import { useSearchParams } from 'react-router';
|
import { useSearchParams } from 'react-router';
|
||||||
import {
|
import {
|
||||||
|
confirmSmsOtp,
|
||||||
loginOrSignUpWithOtp,
|
loginOrSignUpWithOtp,
|
||||||
sendEmailOtp,
|
sendEmailOtp,
|
||||||
sendSmsOtp,
|
sendSmsOtp,
|
||||||
@@ -21,7 +22,7 @@ interface VerifyPhoneNumberProps {
|
|||||||
email: string;
|
email: string;
|
||||||
countryCode: CountryCode;
|
countryCode: CountryCode;
|
||||||
onEditValue: () => void;
|
onEditValue: () => void;
|
||||||
onPhoneNumberVerified: (userId: GUID) => void;
|
onPhoneNumberVerified: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VerifyPhoneNumber({
|
export function VerifyPhoneNumber({
|
||||||
@@ -86,18 +87,16 @@ export function VerifyPhoneNumber({
|
|||||||
setOtpDigitInvalid(false);
|
setOtpDigitInvalid(false);
|
||||||
setVerifyStatusLoading(true);
|
setVerifyStatusLoading(true);
|
||||||
|
|
||||||
const loginRequest: LoginRequest = {
|
const confirmSmsOtpRequest: ConfirmSmsOtpRequest = {
|
||||||
otpCode: otpCode,
|
otpCode: otpCode,
|
||||||
phoneNumber: countryCode + value,
|
phoneNumber: countryCode + value,
|
||||||
email: email,
|
|
||||||
returnUrl: authReturnUrl,
|
|
||||||
};
|
};
|
||||||
const result = await loginOrSignUpWithOtp(loginRequest);
|
const result = await confirmSmsOtp(confirmSmsOtpRequest);
|
||||||
const jsonRes = await result.json();
|
const jsonRes = await result.json();
|
||||||
|
|
||||||
if (jsonRes.success) {
|
if (jsonRes.success) {
|
||||||
setVerifyStatus('success');
|
setVerifyStatus('success');
|
||||||
onPhoneNumberVerified(jsonRes.userId);
|
onPhoneNumberVerified();
|
||||||
} else {
|
} else {
|
||||||
setVerifyStatus('failed');
|
setVerifyStatus('failed');
|
||||||
setErrorMessage(jsonRes.message);
|
setErrorMessage(jsonRes.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user