From b1d2e311e658445a7fee18d35b4611df2820725f Mon Sep 17 00:00:00 2001 From: bipproduction Date: Mon, 24 Nov 2025 11:04:45 +0800 Subject: [PATCH] tambahan --- src/pages/dashboard/dashboard_layout.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pages/dashboard/dashboard_layout.tsx b/src/pages/dashboard/dashboard_layout.tsx index c074053..20510a7 100644 --- a/src/pages/dashboard/dashboard_layout.tsx +++ b/src/pages/dashboard/dashboard_layout.tsx @@ -24,7 +24,7 @@ import { IconDashboard, } from "@tabler/icons-react"; import type { User } from "generated/prisma"; -import { Outlet, useLocation, useNavigate } from "react-router-dom"; +import { Navigate, Outlet, useLocation, useNavigate } from "react-router-dom"; import { default as clientRoute, @@ -59,6 +59,24 @@ export default function DashboardLayout() { defaultValue: true, }); + const [isAuthenticated, setIsAuthenticated] = useState(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 ; + return (