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 {
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loggedIn) {
|
||||||
|
setAuth(AuthState.LoggedIn);
|
||||||
|
|
||||||
|
// if we are on the login screen, redirect to the root
|
||||||
|
if (pathname === "/login") {
|
||||||
|
router.push("/");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
switch (pathname) {
|
switch (pathname) {
|
||||||
case "/datenschutz":
|
case "/datenschutz":
|
||||||
case "/impressum":
|
case "/impressum":
|
||||||
setAuth(AuthState.NoLongSite);
|
setAuth(AuthState.NoLoginSite);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case "/login":
|
case "/login":
|
||||||
if (loggedIn) {
|
|
||||||
router.push("/");
|
|
||||||
} else {
|
|
||||||
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 "";
|
||||||
|
|||||||
Reference in New Issue
Block a user