update check session working,

This commit is contained in:
louiscklaw
2025-05-14 18:10:22 +08:00
parent 0fcc194860
commit 05c69481b5
2 changed files with 109 additions and 20 deletions

View 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 &rarr;
</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;

View File

@@ -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'}>