This commit is contained in:
bipproduction
2025-11-24 11:15:08 +08:00
parent b1d2e311e6
commit 6d5946cd68

View File

@@ -31,6 +31,7 @@ import {
default as clientRoutes,
} from "@/clientRoutes";
import apiFetch from "@/lib/apiFetch";
import ProtectedRoute from "@/components/ProtectedRoute";
/* ----------------------- Logout ----------------------- */
function Logout() {
@@ -59,23 +60,6 @@ export default function DashboardLayout() {
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 (
<AppShell
@@ -141,8 +125,7 @@ export default function DashboardLayout() {
</Title>
</Flex>
</Paper>
<Outlet />
<ProtectedRoute />
</Stack>
</AppShell.Main>
</AppShell>