import { redirect } from '@sveltejs/kit'; import { user } from '#lib/auth/store.svelte.js'; import type { LayoutLoad } from './$types'; // Hard route gate: the Collection is an admin's. SvelteKit runs layout loads // side by side, so this waits for the root +layout.ts to finish signing the // user in; otherwise opening a Collection page directly (a refresh, a // bookmark) would find no user yet and bounce an admin to Home. export const load: LayoutLoad = async ({ parent }) => { await parent(); if (!user.value || !user.value.is_admin) { throw redirect(302, '/'); } return {}; };