From c991270c27293f9a0c0f498e511237ec8c609bc1 Mon Sep 17 00:00:00 2001 From: Dwiky Rizky Ananditya Date: Sun, 31 Mar 2024 10:54:55 +0700 Subject: [PATCH] feat: admin middleware and route --- src/routes/_admin.tsx | 9 +++++++++ src/routes/_admin/dashboard.tsx | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/routes/_admin.tsx create mode 100644 src/routes/_admin/dashboard.tsx diff --git a/src/routes/_admin.tsx b/src/routes/_admin.tsx new file mode 100644 index 0000000..894ecaf --- /dev/null +++ b/src/routes/_admin.tsx @@ -0,0 +1,9 @@ +import { createFileRoute, redirect } from "@tanstack/react-router"; + +export const Route = createFileRoute("/_admin")({ + beforeLoad: async ({ context: { session, isAdmin } }) => { + if (session && !isAdmin) { + throw redirect({ to: "/" }); + } + }, +}); diff --git a/src/routes/_admin/dashboard.tsx b/src/routes/_admin/dashboard.tsx new file mode 100644 index 0000000..7d1168c --- /dev/null +++ b/src/routes/_admin/dashboard.tsx @@ -0,0 +1,9 @@ +import { createFileRoute } from "@tanstack/react-router"; + +export const Route = createFileRoute("/_admin/dashboard")({ + component: Dashboard, +}); + +function Dashboard() { + return
Dashboard
; +}