Fix Ga Perlu Akses Login Saat Ke Semua Fitur Dashboard

This commit is contained in:
2026-03-25 15:35:20 +08:00
parent 7c8012d277
commit 5c09e7a0be
6 changed files with 18 additions and 45 deletions

View File

@@ -114,13 +114,6 @@ const KeamananPage = () => {
return (
<Stack gap="lg">
{/* Page Header */}
<Group justify="space-between" align="center">
<Title order={2} c={dark ? "dark.0" : "black"}>
Keamanan Lingkungan Desa
</Title>
</Group>
<Grid gutter="md">
{/* Peta Keamanan CCTV */}
<GridCol span={{ base: 12, lg: 6 }}>

View File

@@ -61,19 +61,11 @@ type RouteRule = {
const routeRules: RouteRule[] = [
// Public routes - no auth required
{
match: (p) => p === "/" || p === "/signin" || p === "/signup",
requireAuth: false,
},
// Profile routes - auth required for all roles
{
match: (p) => p === "/profile" || p.startsWith("/profile/"),
requireAuth: true,
redirectTo: "/signin",
},
// Dashboard and main pages - auth required for all roles (not just admin)
{
match: (p) =>
p === "/" ||
p === "/signin" ||
p === "/signup" ||
p.startsWith("/kinerja-divisi") ||
p.startsWith("/pengaduan") ||
p.startsWith("/jenna") ||
@@ -83,7 +75,13 @@ const routeRules: RouteRule[] = [
p.startsWith("/sosial") ||
p.startsWith("/keamanan") ||
p.startsWith("/bantuan") ||
p.startsWith("/pengaturan"),
p.startsWith("/pengaturan") ||
p.startsWith("/users"),
requireAuth: false,
},
// Profile routes - auth required for all roles
{
match: (p) => p === "/profile" || p.startsWith("/profile/"),
requireAuth: true,
redirectTo: "/signin",
},

View File

@@ -8,21 +8,15 @@ import { createRootRoute, Outlet } from "@tanstack/react-router";
export const Route = createRootRoute({
component: RootComponent,
beforeLoad: async ({ location }) => {
// Only apply auth middleware for routes that need it
// Public routes: /, /signin, /signup
const isPublicRoute =
location.pathname === "/" ||
location.pathname === "/signin" ||
location.pathname === "/signup";
if (isPublicRoute) {
return;
}
// Apply protected route middleware for all other routes
// Apply protected route middleware for all routes
// The middleware will determine which routes are public vs protected
const context = await protectedRouteMiddleware({ location });
authStore.user = context?.user as any;
authStore.session = context?.session as any;
// Only set auth store if we have user data (for protected routes)
if (context?.user) {
authStore.user = context?.user as any;
authStore.session = context?.session as any;
}
},
});

View File

@@ -37,10 +37,6 @@ import { authStore } from "../../store/auth";
export const Route = createFileRoute("/admin")({
component: DashboardLayout,
beforeLoad: protectedRouteMiddleware,
onEnter({ context }) {
authStore.user = context?.user as any;
authStore.session = context?.session as any;
},
});
function DashboardLayout() {

View File

@@ -21,10 +21,6 @@ import { authStore } from "../../store/auth";
export const Route = createFileRoute("/profile/edit")({
component: EditProfile,
beforeLoad: protectedRouteMiddleware,
onEnter({ context }) {
authStore.user = context?.user as any;
authStore.session = context?.session as any;
},
});
function EditProfile() {

View File

@@ -41,10 +41,6 @@ import { authStore } from "../../store/auth";
export const Route = createFileRoute("/profile/")({
component: Profile,
beforeLoad: protectedRouteMiddleware,
onEnter({ context }) {
authStore.user = context?.user as any;
authStore.session = context?.session as any;
},
});
function Profile() {