Redirect to / if connected

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-12-10 09:40:09 +01:00
parent 5f8333e3f6
commit 0749bed223
2 changed files with 23 additions and 2 deletions
+13
View File
@@ -1,8 +1,21 @@
import styles from "./LoginPage.module.css";
import LoginForm from "../../components/loginform/loginForm.jsx";
import Background from "../../components/background/background.jsx";
import { useEffect, useContext } from "react";
import { AuthContext } from "../../contexts/auth/AuthContext.js";
import { useNavigate } from "react-router";
function LoginPage() {
const { user, loading } = useContext(AuthContext)
const navigate = useNavigate();
useEffect(() => {
if (!loading && user) {
navigate("/");
}
}, [loading, user]);
return (
<Background>
<div className={styles.container}>
+10 -2
View File
@@ -2,10 +2,10 @@ import styles from "./RegisterPage.module.css";
import Background from "../../components/background/background.jsx";
import Input from "../../components/ui/input/input.jsx";
import Button from "../../components/ui/button/button.jsx";
import { useState } from "react";
import {useContext, useEffect, useState} from "react";
import register from "../../utils/register.js";
import { useNavigate } from "react-router";
import {isNumber} from "chart.js/helpers";
import { AuthContext } from "../../contexts/auth/AuthContext.js";
function RegisterPage() {
@@ -19,6 +19,14 @@ function RegisterPage() {
const [name, setName] = useState("");
const [lastName, setLastName] = useState("");
const { user, loading } = useContext(AuthContext)
useEffect(() => {
if (!loading && user) {
navigate("/");
}
}, [loading, user]);
async function handleSubmit(e) {
e.preventDefault();