fixed redirect bug for loggedin users
All checks were successful
Create and publish the Docker image / build-and-push-image (push) Successful in 1m21s

This commit is contained in:
z1glr
2025-10-04 15:45:36 +00:00
parent 16ac2b28cc
commit b95eadcb00

View File

@@ -9,7 +9,7 @@ import React, { useEffect, useState } from "react";
enum AuthState { enum AuthState {
LoggedIn, LoggedIn,
LoginScreen, LoginScreen,
NoLongSite, NoLoginSite,
Unauthorized, Unauthorized,
Loading, Loading,
} }
@@ -39,21 +39,29 @@ export default function Main({ children }: { children: React.ReactNode }) {
zustand.getState().reset(); zustand.getState().reset();
} }
switch (pathname) { if (loggedIn) {
case "/datenschutz": setAuth(AuthState.LoggedIn);
case "/impressum":
setAuth(AuthState.NoLongSite); // if we are on the login screen, redirect to the root
return; if (pathname === "/login") {
case "/login": router.push("/");
if (loggedIn) { }
router.push("/"); } else {
} else { switch (pathname) {
case "/datenschutz":
case "/impressum":
setAuth(AuthState.NoLoginSite);
return;
case "/login":
setAuth(AuthState.LoginScreen); setAuth(AuthState.LoginScreen);
} return;
return;
default: default:
setAuth(AuthState.Unauthorized); setAuth(AuthState.Unauthorized);
router.push("/login"); router.push("/login");
return;
}
} }
})(); })();
}, [pathname, router]); }, [pathname, router]);
@@ -63,7 +71,7 @@ export default function Main({ children }: { children: React.ReactNode }) {
return <Loading />; return <Loading />;
case AuthState.LoggedIn: case AuthState.LoggedIn:
case AuthState.LoginScreen: case AuthState.LoginScreen:
case AuthState.NoLongSite: case AuthState.NoLoginSite:
return children; return children;
case AuthState.Unauthorized: case AuthState.Unauthorized:
return ""; return "";