tambahan
This commit is contained in:
@@ -24,7 +24,7 @@ import {
|
|||||||
IconDashboard,
|
IconDashboard,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import type { User } from "generated/prisma";
|
import type { User } from "generated/prisma";
|
||||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
import { Navigate, Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
default as clientRoute,
|
default as clientRoute,
|
||||||
@@ -59,6 +59,24 @@ export default function DashboardLayout() {
|
|||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function checkSession() {
|
||||||
|
try {
|
||||||
|
// backend otomatis baca cookie JWT dari request
|
||||||
|
const res = await apiFetch.api.user.find.get();
|
||||||
|
setIsAuthenticated(res.status === 200);
|
||||||
|
} catch {
|
||||||
|
setIsAuthenticated(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkSession();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (isAuthenticated === null) return null;
|
||||||
|
if (!isAuthenticated) return <Navigate to={clientRoutes["/login"]} replace />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppShell
|
<AppShell
|
||||||
padding="md"
|
padding="md"
|
||||||
|
|||||||
Reference in New Issue
Block a user