Merge pull request #28 from rkheftan/hotfix/signup-not-redirect
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 { isNumeric } from '@/utils/regexes/isNumeric';
|
||||||
import { CompleteSignUp } from './CompleteSignUp';
|
import { CompleteSignUp } from './CompleteSignUp';
|
||||||
import { EnterPasswordForm } from './EnterPasswordForm';
|
import { EnterPasswordForm } from './EnterPasswordForm';
|
||||||
import { UserStatus } from '../../types/userTypes';
|
import { UserStatus, type LoginResult } from '../../types/userTypes';
|
||||||
import type { CountryCode } from '@/types/commonTypes';
|
import type { CountryCode } from '@/types/commonTypes';
|
||||||
import { VerifyPhoneNumber } from './VerifyPhoneNumber';
|
import { VerifyPhoneNumber } from './VerifyPhoneNumber';
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
@@ -49,12 +49,22 @@ export const AuthenticationSteps = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUserLoggedIn = () => {
|
const handleUserLoggedIn = (loginResult: LoginResult) => {
|
||||||
redirectToReturnUrl();
|
if (loginResult.registeredWithOutPhoneNumber) {
|
||||||
};
|
setCurrentStep('addPhoneNumber');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const handleConfrimPhoneNumber = () => {
|
if (!loginResult.completedUserInformation) {
|
||||||
setCurrentStep('addPhoneNumber');
|
if (authReturnUrl) {
|
||||||
|
navigate(`/signup?returnUrl=${authReturnUrl}`);
|
||||||
|
} else {
|
||||||
|
navigate(`/signup`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectToReturnUrl();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePhoneNumberVerified = () => {
|
const handlePhoneNumberVerified = () => {
|
||||||
@@ -95,7 +105,6 @@ export const AuthenticationSteps = (): JSX.Element => {
|
|||||||
|
|
||||||
{currentStep === 'verify' && (
|
{currentStep === 'verify' && (
|
||||||
<OtpVerifyForm
|
<OtpVerifyForm
|
||||||
onVerifyPhoneNumber={handleConfrimPhoneNumber}
|
|
||||||
authReturnUrl={authReturnUrlOrDefault}
|
authReturnUrl={authReturnUrlOrDefault}
|
||||||
countryCode={countryCode}
|
countryCode={countryCode}
|
||||||
onOTPVerified={handleUserLoggedIn}
|
onOTPVerified={handleUserLoggedIn}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
sendEmailOtp,
|
sendEmailOtp,
|
||||||
sendSmsOtp,
|
sendSmsOtp,
|
||||||
} from '../../api/authorizationAPI';
|
} from '../../api/authorizationAPI';
|
||||||
import type { PasswordLoginRequest } from '../../types/userTypes';
|
import type { LoginResult, PasswordLoginRequest } from '../../types/userTypes';
|
||||||
import { Icon, useToast } from '@rkheftan/harmony-ui';
|
import { Icon, useToast } from '@rkheftan/harmony-ui';
|
||||||
import { useApi } from '@/hooks/useApi';
|
import { useApi } from '@/hooks/useApi';
|
||||||
import { useAuth } from '@/hooks/useAuth';
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
@@ -27,7 +27,7 @@ import { generateTokenWithPassword } from '../../api/identityAPI';
|
|||||||
export interface EnterPasswordFormProps {
|
export interface EnterPasswordFormProps {
|
||||||
onEditValue: () => void;
|
onEditValue: () => void;
|
||||||
onLoginWithOTP: () => void;
|
onLoginWithOTP: () => void;
|
||||||
onLoggedIn: (userId: GUID) => void;
|
onLoggedIn: (loginResult: LoginResult) => void;
|
||||||
emailOrPhone: string;
|
emailOrPhone: string;
|
||||||
authType: AuthType;
|
authType: AuthType;
|
||||||
loginRegisterValue: string;
|
loginRegisterValue: string;
|
||||||
@@ -87,7 +87,7 @@ export const EnterPasswordForm = ({
|
|||||||
...tokenRes.data,
|
...tokenRes.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
onLoggedIn(res.userId);
|
onLoggedIn(res);
|
||||||
toast({
|
toast({
|
||||||
message: t('verify.youHaveSuccessfullyLoggedIn'),
|
message: t('verify.youHaveSuccessfullyLoggedIn'),
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import type {
|
import type {
|
||||||
GoogleCodeClientResponse,
|
GoogleCodeClientResponse,
|
||||||
LoginOrSignUpWithGoogleRequest,
|
LoginOrSignUpWithGoogleRequest,
|
||||||
|
LoginResult,
|
||||||
} from '../../types/userTypes';
|
} from '../../types/userTypes';
|
||||||
import { loginOrSignUpWithGoogle } from '../../api/authorizationAPI';
|
import { loginOrSignUpWithGoogle } from '../../api/authorizationAPI';
|
||||||
import type { GUID } from '@/types/commonTypes';
|
import type { GUID } from '@/types/commonTypes';
|
||||||
@@ -16,7 +17,7 @@ import { useAuth } from '@/hooks/useAuth';
|
|||||||
export interface GoogleAuthenticationProps {
|
export interface GoogleAuthenticationProps {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
authReturnUrl: string;
|
authReturnUrl: string;
|
||||||
onGoogleAuthenticated: (userId: GUID) => void;
|
onGoogleAuthenticated: (loginResult: LoginResult) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GoogleAuthentication = ({
|
export const GoogleAuthentication = ({
|
||||||
@@ -59,7 +60,7 @@ export const GoogleAuthentication = ({
|
|||||||
...tokenRes.data,
|
...tokenRes.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
onGoogleAuthenticated(res.userId);
|
onGoogleAuthenticated(res);
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
message: t('loginForm.googleAuthenticationFailed'),
|
message: t('loginForm.googleAuthenticationFailed'),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AuthType } from '../../types/authTypes';
|
|||||||
import { isEmail } from '@/utils/regexes/isEmail';
|
import { isEmail } from '@/utils/regexes/isEmail';
|
||||||
import { AuthenticationCard } from '../AuthenticationCard';
|
import { AuthenticationCard } from '../AuthenticationCard';
|
||||||
import { CountryCodeSelector } from '../CountryCodeSelector';
|
import { CountryCodeSelector } from '../CountryCodeSelector';
|
||||||
import type { UserStatus } from '../../types/userTypes';
|
import type { LoginResult, UserStatus } from '../../types/userTypes';
|
||||||
import { getUserStatusByPhoneNumberOrEmail } from '../../api/authorizationAPI';
|
import { getUserStatusByPhoneNumberOrEmail } from '../../api/authorizationAPI';
|
||||||
import type { CountryCode, GUID } from '@/types/commonTypes';
|
import type { CountryCode, GUID } from '@/types/commonTypes';
|
||||||
import { GoogleAuthentication } from './GoogleAuthentication';
|
import { GoogleAuthentication } from './GoogleAuthentication';
|
||||||
@@ -23,7 +23,7 @@ export interface LoginRegisterFormProps {
|
|||||||
setAuthType: Dispatch<AuthType>;
|
setAuthType: Dispatch<AuthType>;
|
||||||
onLoginRegisterSubmit: (value: string, userStatus: UserStatus) => void;
|
onLoginRegisterSubmit: (value: string, userStatus: UserStatus) => void;
|
||||||
authReturnUrl: string;
|
authReturnUrl: string;
|
||||||
onGoogleAuthenticated: (userId: GUID) => void;
|
onGoogleAuthenticated: (loginResult: LoginResult) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LoginRegisterForm({
|
export function LoginRegisterForm({
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import DigitInput from '@/components/DigitsInput';
|
|||||||
import type { AuthMode, AuthType } from '../../types/authTypes';
|
import type { AuthMode, AuthType } from '../../types/authTypes';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { AuthenticationCard } from '../AuthenticationCard';
|
import { AuthenticationCard } from '../AuthenticationCard';
|
||||||
import type { LoginRequest } from '../../types/userTypes';
|
import type { LoginRequest, LoginResult } from '../../types/userTypes';
|
||||||
import {
|
import {
|
||||||
loginOrSignUpWithOtp,
|
loginOrSignUpWithOtp,
|
||||||
sendEmailOtp,
|
sendEmailOtp,
|
||||||
@@ -23,8 +23,7 @@ interface OtpVerifyFormProps {
|
|||||||
authType: AuthType;
|
authType: AuthType;
|
||||||
authMode: AuthMode;
|
authMode: AuthMode;
|
||||||
onEditValue: () => void;
|
onEditValue: () => void;
|
||||||
onOTPVerified: (userId: GUID) => void;
|
onOTPVerified: (loginResult: LoginResult) => void;
|
||||||
onVerifyPhoneNumber: (userId: GUID) => void;
|
|
||||||
authReturnUrl: string;
|
authReturnUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +34,6 @@ export function OtpVerifyForm({
|
|||||||
authMode,
|
authMode,
|
||||||
onEditValue,
|
onEditValue,
|
||||||
onOTPVerified,
|
onOTPVerified,
|
||||||
onVerifyPhoneNumber,
|
|
||||||
authReturnUrl,
|
authReturnUrl,
|
||||||
}: OtpVerifyFormProps) {
|
}: OtpVerifyFormProps) {
|
||||||
const [otpCode, setOtpCode] = useState<string>('');
|
const [otpCode, setOtpCode] = useState<string>('');
|
||||||
@@ -118,11 +116,7 @@ export function OtpVerifyForm({
|
|||||||
...tokenRes.data,
|
...tokenRes.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.registeredWithOutPhoneNumber) {
|
onOTPVerified(res);
|
||||||
onVerifyPhoneNumber(res.userId);
|
|
||||||
} else {
|
|
||||||
onOTPVerified(res.userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
message:
|
message:
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ export interface PasswordLoginRequest {
|
|||||||
returnUrl: string;
|
returnUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginResponse extends ApiResponse {
|
export interface LoginResponse extends ApiResponse, LoginResult {}
|
||||||
|
|
||||||
|
export interface LoginResult {
|
||||||
returnUrl: string;
|
returnUrl: string;
|
||||||
userId: GUID;
|
userId: GUID;
|
||||||
registeredWithOutPhoneNumber: boolean;
|
registeredWithOutPhoneNumber: boolean;
|
||||||
@@ -109,9 +111,6 @@ export interface LoginOrSignUpWithGoogleRequest {
|
|||||||
returnUrl: string;
|
returnUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginOrSignUpWithGoogleResponse extends ApiResponse {
|
export interface LoginOrSignUpWithGoogleResponse
|
||||||
userId: GUID;
|
extends ApiResponse,
|
||||||
registeredWithOutPhoneNumber: boolean;
|
LoginResult {}
|
||||||
completedUserInformation: boolean;
|
|
||||||
returnUrl: string;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user