update check session working,
This commit is contained in:
107
002_source/ionic_mobile/src/pages/auth/Home/index copy.tsx
Normal file
107
002_source/ionic_mobile/src/pages/auth/Home/index copy.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
import {
|
||||
IonButton,
|
||||
IonCardTitle,
|
||||
IonCol,
|
||||
IonContent,
|
||||
IonFooter,
|
||||
IonGrid,
|
||||
IonHeader,
|
||||
IonImg,
|
||||
IonPage,
|
||||
IonRouterLink,
|
||||
IonRow,
|
||||
IonToolbar,
|
||||
useIonRouter,
|
||||
} from '@ionic/react';
|
||||
// import { Action } from '../components/Action';
|
||||
import styles from './style.module.scss';
|
||||
import { Action } from '../../../components/Action';
|
||||
import { Paths } from '../../../Paths';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useUser } from '../../../hooks/use-user';
|
||||
import { LoadingScreen } from '../../../components/LoadingScreen';
|
||||
|
||||
const AuthHome = () => {
|
||||
const { t } = useTranslation();
|
||||
const { user, checkSession, isLoading } = useUser();
|
||||
const router = useIonRouter();
|
||||
|
||||
const [showLoading, setShowLoading] = useState<boolean>(true);
|
||||
const [showError, setShowErrr] = useState<{ show: boolean; message: string }>({
|
||||
show: false,
|
||||
message: '',
|
||||
});
|
||||
|
||||
const [checkingSession, setCheckingSession] = useState<boolean>(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!checkingSession) {
|
||||
if (!user) {
|
||||
router.push(Paths.AuthLogin);
|
||||
} else {
|
||||
router.push(Paths.AuthorizedTest);
|
||||
}
|
||||
setShowLoading(false);
|
||||
}
|
||||
}, [user, checkingSession]);
|
||||
|
||||
useEffect(() => {
|
||||
checkSession?.()
|
||||
.then(() => {
|
||||
setCheckingSession(false);
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
}, [checkSession]);
|
||||
|
||||
if (showLoading) return <LoadingScreen />;
|
||||
// if (showError) return <>{showError.message}</>;
|
||||
|
||||
return (
|
||||
<IonPage className={'styles.homePage'}>
|
||||
<IonHeader>
|
||||
{/* <IonToolbar className="ion-no-margin ion-no-padding"> */}
|
||||
<IonImg src="/assets/login2.jpeg" />
|
||||
{/* </IonToolbar> */}
|
||||
</IonHeader>
|
||||
<IonContent fullscreen>
|
||||
<div className={styles.getStarted}>
|
||||
<IonGrid>
|
||||
<IonRow className={`ion-text-center ion-justify-content-center ${styles.heading}`}>
|
||||
<IonCol size="11" className={styles.headingText}>
|
||||
<IonCardTitle>
|
||||
{/* */}
|
||||
Join millions of other people discovering their creative side
|
||||
</IonCardTitle>
|
||||
</IonCol>
|
||||
</IonRow>
|
||||
|
||||
<IonRow className={`ion-text-center ion-justify-content-center`}>
|
||||
<IonRouterLink routerLink={Paths.AuthSignUp} className="custom-link">
|
||||
<IonCol size="11">
|
||||
<IonButton className={`${styles.getStartedButton} custom-button`}>
|
||||
{/* */}
|
||||
Get started →
|
||||
</IonButton>
|
||||
</IonCol>
|
||||
</IonRouterLink>
|
||||
</IonRow>
|
||||
</IonGrid>
|
||||
</div>
|
||||
</IonContent>
|
||||
|
||||
<IonFooter>
|
||||
<IonGrid style={{ marginBottom: '1rem' }}>
|
||||
<Action
|
||||
message={t('already-got-an-account')}
|
||||
text={t('login')}
|
||||
link={Paths.AuthLogin}
|
||||
//
|
||||
/>
|
||||
</IonGrid>
|
||||
</IonFooter>
|
||||
</IonPage>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthHome;
|
@@ -24,37 +24,19 @@ import { LoadingScreen } from '../../../components/LoadingScreen';
|
||||
|
||||
const AuthHome = () => {
|
||||
const { t } = useTranslation();
|
||||
const { user, checkSession } = useUser();
|
||||
const router = useIonRouter();
|
||||
|
||||
const [showLoading, setShowLoading] = useState<boolean>(true);
|
||||
const [showError, setShowErrr] = useState<{ show: boolean; message: string }>({
|
||||
show: false,
|
||||
message: '',
|
||||
});
|
||||
const [checkingSession, setCheckingSession] = useState<boolean>(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!checkingSession) {
|
||||
if (!user) {
|
||||
router.push(Paths.AuthLogin);
|
||||
} else {
|
||||
router.push(Paths.AuthorizedTest);
|
||||
}
|
||||
}
|
||||
setShowLoading(false);
|
||||
}, [user, checkingSession]);
|
||||
|
||||
useEffect(() => {
|
||||
checkSession?.()
|
||||
.then(() => {
|
||||
setCheckingSession(false);
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
}, [checkSession]);
|
||||
}, []);
|
||||
|
||||
if (showLoading) return <LoadingScreen />;
|
||||
// if (showError) return <>{showError.message}</>;
|
||||
if (showError.show) return <>{showError.message}</>;
|
||||
|
||||
return (
|
||||
<IonPage className={'styles.homePage'}>
|
||||
|
Reference in New Issue
Block a user