fixed redirect bug for loggedin users
All checks were successful
Create and publish the Docker image / build-and-push-image (push) Successful in 1m21s
All checks were successful
Create and publish the Docker image / build-and-push-image (push) Successful in 1m21s
This commit is contained in:
@@ -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 <Loading />;
|
||||
case AuthState.LoggedIn:
|
||||
case AuthState.LoginScreen:
|
||||
case AuthState.NoLongSite:
|
||||
case AuthState.NoLoginSite:
|
||||
return children;
|
||||
case AuthState.Unauthorized:
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user