feat: login with google added

This commit is contained in:
مهرزاد قدرتی
2025-08-10 15:37:09 +03:30
parent 945aa379ea
commit a4ee95832f
8 changed files with 163 additions and 93 deletions

View File

@@ -13,8 +13,13 @@ import {
import { UserStatus } from '../../types/userTypes';
import type { CountryCode, GUID } from '@/types/commonTypes';
import { VerifyPhoneNumber } from './VerifyPhoneNumber';
import { useSearchParams } from 'react-router';
export const AuthenticationSteps = (): JSX.Element => {
const DEFAULT_RETURN_URL = 'https://account.business-harmony.com/';
const [searchParams] = useSearchParams();
const authReturnUrl: string =
searchParams.get('returnUrl') ?? DEFAULT_RETURN_URL;
const [authMode, setAuthMode] = useState<AuthMode>('register');
const [authType, setAuthType] = useState<AuthType>('phone');
const [currentStep, setCurrentStep] = useState<
@@ -55,50 +60,26 @@ export const AuthenticationSteps = (): JSX.Element => {
const handleOTPVerfied = (
registeredWithoutPhoneNumber: boolean = false,
userId: GUID,
returnUrl?: string,
) => {
localStorage.setItem('userID', userId);
// if (registeredWithoutPhoneNumber) {
// setCurrentStep('addPhoneNumber');
// }
if (returnUrl) {
location.href = returnUrl;
if (registeredWithoutPhoneNumber) {
setCurrentStep('addPhoneNumber');
}
handleUserLoggedIn(userId);
};
const handleEditValue = () => {
setCurrentStep('emailOrPhone');
};
const handleCompleteSignUp = (countryCode: string, value: string) => {
setCurrentStep('addedPhoneNumberVerify');
};
const handleCompleteSignUpOTPVerified = () => {
console.log('phoneNumberVerified');
};
const handleCompleteSignUpEditValue = () => {
setCurrentStep('emailOrPhone');
};
const handleLoggedInWithPassowrd = (userId: GUID, returnUrl?: string) => {
const handleUserLoggedIn = (userId: GUID) => {
localStorage.setItem('userID', userId);
if (returnUrl) {
location.href = returnUrl;
}
};
const handleLoginWithOtpInsteadOfPassword = async () => {
setCurrentStep('verify');
location.href = authReturnUrl;
};
return (
<>
{currentStep === 'emailOrPhone' && (
<LoginRegisterForm
authReturnUrl={authReturnUrl}
onGoogleAuthenticated={handleUserLoggedIn}
countryCode={countryCode}
setCountryCode={setCountryCode}
loginRegisterValue={loginRegisterValue}
@@ -111,9 +92,10 @@ export const AuthenticationSteps = (): JSX.Element => {
{currentStep === 'verify' && (
<OtpVerifyForm
authReturnUrl={authReturnUrl}
countryCode={countryCode}
onOTPVerified={handleOTPVerfied}
onEditValue={handleEditValue}
onEditValue={() => setCurrentStep('emailOrPhone')}
authMode={authMode}
authType={authType}
value={loginRegisterValue}
@@ -122,12 +104,13 @@ export const AuthenticationSteps = (): JSX.Element => {
{currentStep === 'enterPassword' && (
<EnterPasswordForm
authReturnUrl={authReturnUrl}
loginRegisterValue={loginRegisterValue}
countryCode={countryCode}
authType={authType}
onLoggedIn={handleLoggedInWithPassowrd}
onEditValue={handleEditValue}
onLoginWithOTP={handleLoginWithOtpInsteadOfPassword}
onLoggedIn={handleUserLoggedIn}
onEditValue={() => setCurrentStep('emailOrPhone')}
onLoginWithOTP={() => setCurrentStep('verify')}
emailOrPhone={loginRegisterValue}
/>
)}
@@ -137,16 +120,16 @@ export const AuthenticationSteps = (): JSX.Element => {
value={addedPhoneNumberValue}
setValue={setAddedPhoneNumberValue}
email={loginRegisterValue}
onCompleteSignUp={handleCompleteSignUp}
onCompleteSignUp={() => setCurrentStep('addedPhoneNumberVerify')}
/>
)}
{currentStep === 'addedPhoneNumberVerify' && (
<VerifyPhoneNumber
countryCode={countryCode}
onEditValue={handleCompleteSignUpEditValue}
onEditValue={() => setCurrentStep('emailOrPhone')}
value={addedPhoneNumberValue}
onPhoneNumberVerified={handleCompleteSignUpOTPVerified}
onPhoneNumberVerified={handleUserLoggedIn}
/>
)}
</>