fix: login result handle changed to a singular function
This commit is contained in:
@@ -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' && (
|
||||
<OtpVerifyForm
|
||||
onVerifyPhoneNumber={handleConfrimPhoneNumber}
|
||||
authReturnUrl={authReturnUrlOrDefault}
|
||||
countryCode={countryCode}
|
||||
onOTPVerified={handleUserLoggedIn}
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
sendEmailOtp,
|
||||
sendSmsOtp,
|
||||
} from '../../api/authorizationAPI';
|
||||
import type { PasswordLoginRequest } from '../../types/userTypes';
|
||||
import type { LoginResult, PasswordLoginRequest } from '../../types/userTypes';
|
||||
import { Icon, useToast } from '@rkheftan/harmony-ui';
|
||||
import { useApi } from '@/hooks/useApi';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
@@ -27,7 +27,7 @@ import { generateTokenWithPassword } from '../../api/identityAPI';
|
||||
export interface EnterPasswordFormProps {
|
||||
onEditValue: () => 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',
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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<AuthType>;
|
||||
onLoginRegisterSubmit: (value: string, userStatus: UserStatus) => void;
|
||||
authReturnUrl: string;
|
||||
onGoogleAuthenticated: (userId: GUID) => void;
|
||||
onGoogleAuthenticated: (loginResult: LoginResult) => void;
|
||||
}
|
||||
|
||||
export function LoginRegisterForm({
|
||||
|
||||
@@ -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<string>('');
|
||||
@@ -118,11 +116,7 @@ export function OtpVerifyForm({
|
||||
...tokenRes.data,
|
||||
});
|
||||
|
||||
if (res.registeredWithOutPhoneNumber) {
|
||||
onVerifyPhoneNumber(res.userId);
|
||||
} else {
|
||||
onOTPVerified(res.userId);
|
||||
}
|
||||
onOTPVerified(res);
|
||||
|
||||
toast({
|
||||
message:
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user