From b95eadcb001e917c1848b45f498272839c767113 Mon Sep 17 00:00:00 2001 From: z1glr Date: Sat, 4 Oct 2025 15:45:36 +0000 Subject: [PATCH] fixed redirect bug for loggedin users --- client/src/app/Main.tsx | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/client/src/app/Main.tsx b/client/src/app/Main.tsx index 8323a2a..53fee03 100644 --- a/client/src/app/Main.tsx +++ b/client/src/app/Main.tsx @@ -9,7 +9,7 @@ import React, { useEffect, useState } from "react"; enum AuthState { LoggedIn, LoginScreen, - NoLongSite, + NoLoginSite, Unauthorized, Loading, } @@ -39,21 +39,29 @@ export default function Main({ children }: { children: React.ReactNode }) { zustand.getState().reset(); } - switch (pathname) { - case "/datenschutz": - case "/impressum": - setAuth(AuthState.NoLongSite); - return; - case "/login": - if (loggedIn) { - router.push("/"); - } else { + if (loggedIn) { + setAuth(AuthState.LoggedIn); + + // if we are on the login screen, redirect to the root + if (pathname === "/login") { + router.push("/"); + } + } else { + switch (pathname) { + case "/datenschutz": + case "/impressum": + setAuth(AuthState.NoLoginSite); + return; + + case "/login": setAuth(AuthState.LoginScreen); - } - return; - default: - setAuth(AuthState.Unauthorized); - router.push("/login"); + return; + + default: + setAuth(AuthState.Unauthorized); + router.push("/login"); + return; + } } })(); }, [pathname, router]); @@ -63,7 +71,7 @@ export default function Main({ children }: { children: React.ReactNode }) { return ; case AuthState.LoggedIn: case AuthState.LoginScreen: - case AuthState.NoLongSite: + case AuthState.NoLoginSite: return children; case AuthState.Unauthorized: return "";