Fix Ga Perlu Akses Login Saat Ke Semua Fitur Dashboard
This commit is contained in:
@@ -114,13 +114,6 @@ const KeamananPage = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap="lg">
|
<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">
|
<Grid gutter="md">
|
||||||
{/* Peta Keamanan CCTV */}
|
{/* Peta Keamanan CCTV */}
|
||||||
<GridCol span={{ base: 12, lg: 6 }}>
|
<GridCol span={{ base: 12, lg: 6 }}>
|
||||||
|
|||||||
@@ -61,19 +61,11 @@ type RouteRule = {
|
|||||||
|
|
||||||
const routeRules: RouteRule[] = [
|
const routeRules: RouteRule[] = [
|
||||||
// Public routes - no auth required
|
// 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) =>
|
match: (p) =>
|
||||||
|
p === "/" ||
|
||||||
|
p === "/signin" ||
|
||||||
|
p === "/signup" ||
|
||||||
p.startsWith("/kinerja-divisi") ||
|
p.startsWith("/kinerja-divisi") ||
|
||||||
p.startsWith("/pengaduan") ||
|
p.startsWith("/pengaduan") ||
|
||||||
p.startsWith("/jenna") ||
|
p.startsWith("/jenna") ||
|
||||||
@@ -83,7 +75,13 @@ const routeRules: RouteRule[] = [
|
|||||||
p.startsWith("/sosial") ||
|
p.startsWith("/sosial") ||
|
||||||
p.startsWith("/keamanan") ||
|
p.startsWith("/keamanan") ||
|
||||||
p.startsWith("/bantuan") ||
|
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,
|
requireAuth: true,
|
||||||
redirectTo: "/signin",
|
redirectTo: "/signin",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,21 +8,15 @@ import { createRootRoute, Outlet } from "@tanstack/react-router";
|
|||||||
export const Route = createRootRoute({
|
export const Route = createRootRoute({
|
||||||
component: RootComponent,
|
component: RootComponent,
|
||||||
beforeLoad: async ({ location }) => {
|
beforeLoad: async ({ location }) => {
|
||||||
// Only apply auth middleware for routes that need it
|
// Apply protected route middleware for all routes
|
||||||
// Public routes: /, /signin, /signup
|
// The middleware will determine which routes are public vs protected
|
||||||
const isPublicRoute =
|
|
||||||
location.pathname === "/" ||
|
|
||||||
location.pathname === "/signin" ||
|
|
||||||
location.pathname === "/signup";
|
|
||||||
|
|
||||||
if (isPublicRoute) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply protected route middleware for all other routes
|
|
||||||
const context = await protectedRouteMiddleware({ location });
|
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;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ import { authStore } from "../../store/auth";
|
|||||||
export const Route = createFileRoute("/admin")({
|
export const Route = createFileRoute("/admin")({
|
||||||
component: DashboardLayout,
|
component: DashboardLayout,
|
||||||
beforeLoad: protectedRouteMiddleware,
|
beforeLoad: protectedRouteMiddleware,
|
||||||
onEnter({ context }) {
|
|
||||||
authStore.user = context?.user as any;
|
|
||||||
authStore.session = context?.session as any;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function DashboardLayout() {
|
function DashboardLayout() {
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ import { authStore } from "../../store/auth";
|
|||||||
export const Route = createFileRoute("/profile/edit")({
|
export const Route = createFileRoute("/profile/edit")({
|
||||||
component: EditProfile,
|
component: EditProfile,
|
||||||
beforeLoad: protectedRouteMiddleware,
|
beforeLoad: protectedRouteMiddleware,
|
||||||
onEnter({ context }) {
|
|
||||||
authStore.user = context?.user as any;
|
|
||||||
authStore.session = context?.session as any;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function EditProfile() {
|
function EditProfile() {
|
||||||
|
|||||||
@@ -41,10 +41,6 @@ import { authStore } from "../../store/auth";
|
|||||||
export const Route = createFileRoute("/profile/")({
|
export const Route = createFileRoute("/profile/")({
|
||||||
component: Profile,
|
component: Profile,
|
||||||
beforeLoad: protectedRouteMiddleware,
|
beforeLoad: protectedRouteMiddleware,
|
||||||
onEnter({ context }) {
|
|
||||||
authStore.user = context?.user as any;
|
|
||||||
authStore.session = context?.session as any;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function Profile() {
|
function Profile() {
|
||||||
|
|||||||
Reference in New Issue
Block a user