many improvements + added public page

This commit is contained in:
Daniel
2023-05-28 09:25:49 +03:30
parent 19b848ee73
commit dc19638f2c
11 changed files with 229 additions and 159 deletions
+20 -16
View File
@@ -22,22 +22,26 @@ export default function ({ children }: Props) {
getInitialData();
useEffect(() => {
if (
status === "authenticated" &&
(router.pathname === "/login" || router.pathname === "/register")
) {
router.push("/").then(() => {
setRedirect(false);
});
} else if (
status === "unauthenticated" &&
!(router.pathname === "/login" || router.pathname === "/register")
) {
router.push("/login").then(() => {
setRedirect(false);
});
} else if (status === "loading") setRedirect(true);
else setRedirect(false);
if (!router.pathname.startsWith("/public")) {
if (
status === "authenticated" &&
(router.pathname === "/login" || router.pathname === "/register")
) {
router.push("/").then(() => {
setRedirect(false);
});
} else if (
status === "unauthenticated" &&
!(router.pathname === "/login" || router.pathname === "/register")
) {
router.push("/login").then(() => {
setRedirect(false);
});
} else if (status === "loading") setRedirect(true);
else setRedirect(false);
} else {
setRedirect(false);
}
}, [status]);
if (status !== "loading" && !redirect) return <>{children}</>;