tambahan
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
|||||||
default as clientRoutes,
|
default as clientRoutes,
|
||||||
} from "@/clientRoutes";
|
} from "@/clientRoutes";
|
||||||
import apiFetch from "@/lib/apiFetch";
|
import apiFetch from "@/lib/apiFetch";
|
||||||
|
import ProtectedRoute from "@/components/ProtectedRoute";
|
||||||
|
|
||||||
/* ----------------------- Logout ----------------------- */
|
/* ----------------------- Logout ----------------------- */
|
||||||
function Logout() {
|
function Logout() {
|
||||||
@@ -59,23 +60,6 @@ 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
|
||||||
@@ -141,8 +125,7 @@ export default function DashboardLayout() {
|
|||||||
</Title>
|
</Title>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
<ProtectedRoute />
|
||||||
<Outlet />
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</AppShell.Main>
|
</AppShell.Main>
|
||||||
</AppShell>
|
</AppShell>
|
||||||
|
|||||||
Reference in New Issue
Block a user