From b736a00fb1698dbac605bc8d2d1c20a6f71e86c8 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 17 May 2024 10:07:22 +0200 Subject: [PATCH] :bug: Redirect on register if not logged --- frontend-react/src/app/login/page.tsx | 1 - frontend-react/src/app/register/page.tsx | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend-react/src/app/login/page.tsx b/frontend-react/src/app/login/page.tsx index 4e2eec3..72edc97 100644 --- a/frontend-react/src/app/login/page.tsx +++ b/frontend-react/src/app/login/page.tsx @@ -17,7 +17,6 @@ const LoginPage = () => { const [toastType, setToastType] = useState<'success' | 'error'>('success'); const [connectionError, setConnectionError] = useState(false); - // Vérifiez la session dès que le composant est monté useEffect(() => { const checkSession = async () => { const session = await verifySession(); diff --git a/frontend-react/src/app/register/page.tsx b/frontend-react/src/app/register/page.tsx index 85fa062..0592525 100644 --- a/frontend-react/src/app/register/page.tsx +++ b/frontend-react/src/app/register/page.tsx @@ -1,12 +1,13 @@ // src/app/register/page.tsx "use client"; -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import RegisterForm from './form/RegisterForm'; import {useRouter} from 'next/navigation'; import Toast from "@/app/components/toasts"; import {register} from "@/app/register/services/registerService"; import {ApiResponse} from "@/app/api/apiService"; +import {verifySession} from "@/app/lib/dal"; const RegisterPage = () => { const router = useRouter(); @@ -15,6 +16,15 @@ const RegisterPage = () => { const [toastMessage, setToastMessage] = useState(''); const [toastType, setToastType] = useState<'success' | 'error'>('success'); + useEffect(() => { + const checkSession = async () => { + const session = await verifySession(); + if (session) { + router.push('/users'); + } + }; + checkSession().then(r => r); + }, [router]); const handleRegister = async (user: { email: string,