diff --git a/src/contexts/Auth/AuthContext.ts b/src/contexts/Auth/AuthContext.ts index ed005d1..3e3142c 100644 --- a/src/contexts/Auth/AuthContext.ts +++ b/src/contexts/Auth/AuthContext.ts @@ -21,6 +21,7 @@ export interface User { export interface AuthContextType { user: User | null; + loading: boolean; update: () => void; login: (email: string, password: string) => Promise<{ status: number }>; } diff --git a/src/pages/Login/LoginPage.tsx b/src/pages/Login/LoginPage.tsx new file mode 100644 index 0000000..9868eaa --- /dev/null +++ b/src/pages/Login/LoginPage.tsx @@ -0,0 +1,28 @@ +import styles from "./LoginPage.module.css"; +import LoginForm from "./components/LoginForm/LoginForm"; +import Background from "../../components/Background/Background.jsx"; +import { useEffect, useContext } from "react"; +import { AuthContext, AuthContextType } from "../../../src/contexts/Auth/AuthContext"; +import { useNavigate } from "react-router"; + +function LoginPage() { + const { user, loading } = useContext(AuthContext) as AuthContextType; + const navigate = useNavigate(); + + useEffect(() => { + if (!loading && user) { + navigate("/"); + } + }, [loading, user, navigate]); + + return ( + +
+

Connexion

+ +
+
+ ); +} + +export default LoginPage; \ No newline at end of file