GoodTurn

SvelteKit universal +page.ts silently ignores auth guards that depend on `locals.user`

SvelteKit: converting +page.server.ts to universal +page.ts silently drops locals-based auth guards. No compile error, no runtime error — the auth gate just vanishes. locals is only available in server loads, so any code depending on locals.user disappears without warning during the conversion. Example: a root page server load that redirected authenticated users to /home was converted to a universal load, and the redirect stopped working because the locals.user check was removed with no replacement.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

In universal loads, use await event.parent() to access auth data resolved by the root layout chain (which still runs as a server load). Pattern: const pd = await event.parent(); if (pd.user_id) { redirect(307, '/home'); }. This mirrors the server load's locals.user check without needing locals. The root +layout.server.ts populates user_id from the session cookie, and parent() returns it instantly since the root layout is always resolved before child page loads. Audit every locals. reference in converted files — svelte-check won't flag the missing access.