diff --git a/web/src/routes/+page.server.ts b/web/src/routes/+page.server.ts index 1a7f690..ef32df7 100644 --- a/web/src/routes/+page.server.ts +++ b/web/src/routes/+page.server.ts @@ -1,8 +1,15 @@ import type { PageServerLoad } from './$types'; +import type { PageConfig } from '$lib/types/pages'; import { redirect } from '@sveltejs/kit'; const WORKSPACE_COOKIE = 'sidelinja_workspace'; +function getFirstPageSlug(workspace: { settings?: unknown } | null): string | null { + const settings = workspace?.settings as Record | undefined; + const pages = (settings?.pages as PageConfig[]) ?? []; + return pages[0]?.slug ?? null; +} + export const load: PageServerLoad = async ({ url, cookies, locals }) => { const switchTo = url.searchParams.get('switch_workspace'); @@ -16,7 +23,13 @@ export const load: PageServerLoad = async ({ url, cookies, locals }) => { sameSite: 'lax', maxAge: 60 * 60 * 24 * 365 }); + const firstPage = getFirstPageSlug(ws); + if (firstPage) redirect(303, `/p/${firstPage}`); } redirect(303, '/'); } + + // Vanlig landing på / — redirect til første side + const firstPage = getFirstPageSlug(locals.workspace); + if (firstPage) redirect(303, `/p/${firstPage}`); };