From 5c09e7a0be0512a9568dba39472273cfaceaf387 Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 25 Mar 2026 15:35:20 +0800 Subject: [PATCH] Fix Ga Perlu Akses Login Saat Ke Semua Fitur Dashboard --- src/components/keamanan-page.tsx | 7 ------- src/middleware/authMiddleware.tsx | 22 ++++++++++------------ src/routes/__root.tsx | 22 ++++++++-------------- src/routes/admin/route.tsx | 4 ---- src/routes/profile/edit.tsx | 4 ---- src/routes/profile/index.tsx | 4 ---- 6 files changed, 18 insertions(+), 45 deletions(-) diff --git a/src/components/keamanan-page.tsx b/src/components/keamanan-page.tsx index 6453ae1..2cc042d 100644 --- a/src/components/keamanan-page.tsx +++ b/src/components/keamanan-page.tsx @@ -114,13 +114,6 @@ const KeamananPage = () => { return ( - {/* Page Header */} - - - Keamanan Lingkungan Desa - - - {/* Peta Keamanan CCTV */} diff --git a/src/middleware/authMiddleware.tsx b/src/middleware/authMiddleware.tsx index 08e9bd0..4c330ce 100644 --- a/src/middleware/authMiddleware.tsx +++ b/src/middleware/authMiddleware.tsx @@ -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", }, diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index e536635..7396804 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -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; + } }, }); diff --git a/src/routes/admin/route.tsx b/src/routes/admin/route.tsx index 688d779..3bc045a 100644 --- a/src/routes/admin/route.tsx +++ b/src/routes/admin/route.tsx @@ -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() { diff --git a/src/routes/profile/edit.tsx b/src/routes/profile/edit.tsx index 1ec3b2c..1ef6dae 100644 --- a/src/routes/profile/edit.tsx +++ b/src/routes/profile/edit.tsx @@ -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() { diff --git a/src/routes/profile/index.tsx b/src/routes/profile/index.tsx index 98636d4..bb129bf 100644 --- a/src/routes/profile/index.tsx +++ b/src/routes/profile/index.tsx @@ -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() {