added landingpage and fixed routing

This commit is contained in:
2025-10-25 22:41:43 +02:00
parent e9319b49ec
commit 47fec60b5b
3 changed files with 263 additions and 5 deletions

View File

@@ -1,9 +1,20 @@
import { Navigate, Outlet } from "react-router-dom";
import { useAtom } from "jotai";
import { setIsLoggedInAtom } from "@/states/Atoms";
import { Navigate, Outlet, useLocation } from "react-router-dom";
import Cookies from "js-cookie";
import { useContext } from "react";
import { UserContext } from "@/states/Context";
export const ProtectedRoutes = () => {
const [isLoggedIn] = useAtom(setIsLoggedInAtom);
const user = useContext(UserContext);
const location = useLocation();
const hasToken = Boolean(Cookies.get("token"));
return isLoggedIn ? <Outlet /> : <Navigate to="/login" />;
if (hasToken && !user) {
return null;
}
return user ? (
<Outlet />
) : (
<Navigate to="/login" replace state={{ from: location }} />
);
};