diff --git a/src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx b/src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx index bd5ca98..598eaa6 100644 --- a/src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx +++ b/src/features/authentication/components/AuthenticationSteps/AuthenticationSteps.tsx @@ -5,7 +5,7 @@ import { OtpVerifyForm } from './OtpVerifyForm'; import { isNumeric } from '@/utils/regexes/isNumeric'; import { CompleteSignUp } from './CompleteSignUp'; import { EnterPasswordForm } from './EnterPasswordForm'; -import { UserStatus } from '../../types/userTypes'; +import { UserStatus, type LoginResult } from '../../types/userTypes'; import type { CountryCode } from '@/types/commonTypes'; import { VerifyPhoneNumber } from './VerifyPhoneNumber'; import { useNavigate, useSearchParams } from 'react-router-dom'; @@ -49,12 +49,22 @@ export const AuthenticationSteps = (): JSX.Element => { } }; - const handleUserLoggedIn = () => { - redirectToReturnUrl(); - }; + const handleUserLoggedIn = (loginResult: LoginResult) => { + if (loginResult.registeredWithOutPhoneNumber) { + setCurrentStep('addPhoneNumber'); + return; + } - const handleConfrimPhoneNumber = () => { - setCurrentStep('addPhoneNumber'); + if (!loginResult.completedUserInformation) { + if (authReturnUrl) { + navigate(`/signup?returnUrl=${authReturnUrl}`); + } else { + navigate(`/signup`); + } + return; + } + + redirectToReturnUrl(); }; const handlePhoneNumberVerified = () => { @@ -95,7 +105,6 @@ export const AuthenticationSteps = (): JSX.Element => { {currentStep === 'verify' && ( void; onLoginWithOTP: () => void; - onLoggedIn: (userId: GUID) => void; + onLoggedIn: (loginResult: LoginResult) => void; emailOrPhone: string; authType: AuthType; loginRegisterValue: string; @@ -87,7 +87,7 @@ export const EnterPasswordForm = ({ ...tokenRes.data, }); - onLoggedIn(res.userId); + onLoggedIn(res); toast({ message: t('verify.youHaveSuccessfullyLoggedIn'), severity: 'success', diff --git a/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx b/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx index bf3eaea..4273ee5 100644 --- a/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx +++ b/src/features/authentication/components/AuthenticationSteps/GoogleAuthentication.tsx @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'; import type { GoogleCodeClientResponse, LoginOrSignUpWithGoogleRequest, + LoginResult, } from '../../types/userTypes'; import { loginOrSignUpWithGoogle } from '../../api/authorizationAPI'; import type { GUID } from '@/types/commonTypes'; @@ -16,7 +17,7 @@ import { useAuth } from '@/hooks/useAuth'; export interface GoogleAuthenticationProps { disabled: boolean; authReturnUrl: string; - onGoogleAuthenticated: (userId: GUID) => void; + onGoogleAuthenticated: (loginResult: LoginResult) => void; } export const GoogleAuthentication = ({ @@ -59,7 +60,7 @@ export const GoogleAuthentication = ({ ...tokenRes.data, }); - onGoogleAuthenticated(res.userId); + onGoogleAuthenticated(res); } else { toast({ message: t('loginForm.googleAuthenticationFailed'), diff --git a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx b/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx index 5ec85b7..9d61607 100644 --- a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx +++ b/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx @@ -6,7 +6,7 @@ import type { AuthType } from '../../types/authTypes'; import { isEmail } from '@/utils/regexes/isEmail'; import { AuthenticationCard } from '../AuthenticationCard'; import { CountryCodeSelector } from '../CountryCodeSelector'; -import type { UserStatus } from '../../types/userTypes'; +import type { LoginResult, UserStatus } from '../../types/userTypes'; import { getUserStatusByPhoneNumberOrEmail } from '../../api/authorizationAPI'; import type { CountryCode, GUID } from '@/types/commonTypes'; import { GoogleAuthentication } from './GoogleAuthentication'; @@ -23,7 +23,7 @@ export interface LoginRegisterFormProps { setAuthType: Dispatch; onLoginRegisterSubmit: (value: string, userStatus: UserStatus) => void; authReturnUrl: string; - onGoogleAuthenticated: (userId: GUID) => void; + onGoogleAuthenticated: (loginResult: LoginResult) => void; } export function LoginRegisterForm({ diff --git a/src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx b/src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx index 006e0c5..1d02526 100644 --- a/src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx +++ b/src/features/authentication/components/AuthenticationSteps/OtpVerifyForm.tsx @@ -5,7 +5,7 @@ import DigitInput from '@/components/DigitsInput'; import type { AuthMode, AuthType } from '../../types/authTypes'; import { useEffect, useState } from 'react'; import { AuthenticationCard } from '../AuthenticationCard'; -import type { LoginRequest } from '../../types/userTypes'; +import type { LoginRequest, LoginResult } from '../../types/userTypes'; import { loginOrSignUpWithOtp, sendEmailOtp, @@ -23,8 +23,7 @@ interface OtpVerifyFormProps { authType: AuthType; authMode: AuthMode; onEditValue: () => void; - onOTPVerified: (userId: GUID) => void; - onVerifyPhoneNumber: (userId: GUID) => void; + onOTPVerified: (loginResult: LoginResult) => void; authReturnUrl: string; } @@ -35,7 +34,6 @@ export function OtpVerifyForm({ authMode, onEditValue, onOTPVerified, - onVerifyPhoneNumber, authReturnUrl, }: OtpVerifyFormProps) { const [otpCode, setOtpCode] = useState(''); @@ -118,11 +116,7 @@ export function OtpVerifyForm({ ...tokenRes.data, }); - if (res.registeredWithOutPhoneNumber) { - onVerifyPhoneNumber(res.userId); - } else { - onOTPVerified(res.userId); - } + onOTPVerified(res); toast({ message: diff --git a/src/features/authentication/types/userTypes.ts b/src/features/authentication/types/userTypes.ts index b7e4ea6..44ecc84 100644 --- a/src/features/authentication/types/userTypes.ts +++ b/src/features/authentication/types/userTypes.ts @@ -35,7 +35,9 @@ export interface PasswordLoginRequest { returnUrl: string; } -export interface LoginResponse extends ApiResponse { +export interface LoginResponse extends ApiResponse, LoginResult {} + +export interface LoginResult { returnUrl: string; userId: GUID; registeredWithOutPhoneNumber: boolean; @@ -109,9 +111,6 @@ export interface LoginOrSignUpWithGoogleRequest { returnUrl: string; } -export interface LoginOrSignUpWithGoogleResponse extends ApiResponse { - userId: GUID; - registeredWithOutPhoneNumber: boolean; - completedUserInformation: boolean; - returnUrl: string; -} +export interface LoginOrSignUpWithGoogleResponse + extends ApiResponse, + LoginResult {}