From f4089fe1112798019fab6aac75bb2698fc6c74ef Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 31 Mar 2026 22:33:39 +0500 Subject: [PATCH] fix(admin): add layout guard and redirect /admin to /admin/scrape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add +layout.server.ts to enforce admin role check at layout level, preventing 404 on /admin and protecting all sub-routes centrally - Add +page.server.ts to redirect /admin → /admin/scrape (was 404) --- ui/src/routes/admin/+layout.server.ts | 8 ++++++++ ui/src/routes/admin/+page.server.ts | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 ui/src/routes/admin/+layout.server.ts create mode 100644 ui/src/routes/admin/+page.server.ts diff --git a/ui/src/routes/admin/+layout.server.ts b/ui/src/routes/admin/+layout.server.ts new file mode 100644 index 0000000..24471a4 --- /dev/null +++ b/ui/src/routes/admin/+layout.server.ts @@ -0,0 +1,8 @@ +import { redirect } from '@sveltejs/kit'; +import type { LayoutServerLoad } from './$types'; + +export const load: LayoutServerLoad = async ({ locals }) => { + if (locals.user?.role !== 'admin') { + redirect(302, '/'); + } +}; diff --git a/ui/src/routes/admin/+page.server.ts b/ui/src/routes/admin/+page.server.ts new file mode 100644 index 0000000..fdc1ac3 --- /dev/null +++ b/ui/src/routes/admin/+page.server.ts @@ -0,0 +1,6 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; + +export const load: PageServerLoad = async () => { + redirect(302, '/admin/scrape'); +};