@@ -30,7 +30,7 @@ import { userSession, requestSMSToken } from '../../services/api/login.service';
3030
3131// Interface
3232import { IProps , IStates , defaultStates , User , UserRes , LoginType } from './login.interface' ;
33- import usePreventBackNavigation from '../../hooks/usePreventBackNavigation' ;
33+
3434
3535//Components
3636import AccountPage from '../../components/AccountPage' ;
@@ -42,7 +42,6 @@ import { RootState } from '../../store';
4242const Login : FC < IProps > = ( ) => {
4343 const [ data , setData ] = useState < LoginType > ( { } ) ;
4444
45- usePreventBackNavigation ( ) ;
4645
4746 // ************* Fetch Login Data ************
4847 const fetchData = async ( ) => {
@@ -70,7 +69,7 @@ const Login: FC<IProps> = () => {
7069 // ************* ALL States Here ************
7170 const [ loginStates , setLoginStates ] = useState < IStates > ( defaultStates ) ;
7271 const [ isLoading , setIsLoading ] = useState < boolean > ( false )
73- const [ isBlock , setIsBlock ] = useState ( false ) ;
72+ // const [isBlock, setIsBlock] = useState(false);
7473
7574 const navigate = useNavigate ( ) ;
7675 const location = useLocation ( ) ;
@@ -197,13 +196,13 @@ const Login: FC<IProps> = () => {
197196 }
198197 } ;
199198
200- useEffect ( ( ) => {
201- if ( region && loginStates ?. tfa ) {
202- setIsBlock ( true ) ;
199+ // useEffect(()=>{
200+ // if(region && loginStates?.tfa){
201+ // setIsBlock(true);
203202
204- }
203+ // }
205204
206- } , [ loginStates ] ) ;
205+ // },[loginStates]);
207206
208207 // Function for TFA validation
209208 const TFAValidation = ( value : string ) : string | undefined => {
@@ -242,20 +241,43 @@ const Login: FC<IProps> = () => {
242241 } ;
243242 } ;
244243
245- useEffect ( ( ) => {
246- const handlePopState = ( event : PopStateEvent ) => {
247- event . preventDefault ( ) ;
248- window . history . pushState ( null , '' , window . location . href ) ;
244+ // useEffect(()=>{
245+ // const handlePopState = (event: PopStateEvent) => {
246+ // event.preventDefault();
247+ // window.history.pushState(null, '', window.location.href);
248+ // };
249+ // if(isBlock){
250+ // window.history.pushState(null, '', window.location.href);
251+ // }
252+ // window.history.pushState(null, '', window.location.href);
253+ // window.addEventListener('popstate',handlePopState);
254+ // return () => {
255+ // window.removeEventListener('popstate', handlePopState);
256+ // };
257+ // },[isBlock]);
258+
259+ useEffect ( ( ) => {
260+
261+ const redirectUrl = loginStates ?. tfa && region ? `/login?region=${ region } ` : "/region-login"
262+
263+ const handleBackButton = ( ) => {
264+ // Redirect to an internal route
265+ navigate ( redirectUrl , { replace : true } ) ;
249266 } ;
250- if ( isBlock ) {
251- window . history . pushState ( null , '' , window . location . href ) ;
252- }
267+
253268 window . history . pushState ( null , '' , window . location . href ) ;
254- window . addEventListener ( 'popstate' , handlePopState ) ;
269+
270+ const handlePopState = ( ) => {
271+ handleBackButton ( ) ;
272+ } ;
273+
274+ window . addEventListener ( 'popstate' , handlePopState ) ;
275+
255276 return ( ) => {
256277 window . removeEventListener ( 'popstate' , handlePopState ) ;
257278 } ;
258- } , [ isBlock ] ) ;
279+ } , [ navigate , loginStates ] ) ;
280+
259281
260282
261283 return (
0 commit comments