import { redirect } from '@sveltejs/kit'; import type { LayoutServerLoad } from './$types'; import { AUTH_COOKIE_NAME } from '$lib/server/config'; export const load: LayoutServerLoad = async ({ cookies, url }) => { const isLoggedIn = Boolean(cookies.get(AUTH_COOKIE_NAME)); const isLoginRoute = url.pathname === '/admin/login'; if (!isLoggedIn && !isLoginRoute) { throw redirect(302, '/admin/login'); } return { isLoggedIn }; };