fix(web): opening an admin or Collection page directly no longer bounces an admin to Home

The two route gates read the signed-in user without waiting for the root
layout to load it. SvelteKit runs layout loads side by side, so a
refresh or a bookmark found no user yet and redirected to Home. Each gate
now awaits parent() before it judges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:05:58 -05:00
co-authored by Claude Opus 5.5
parent c4eaa33e24
commit 55a6f1e437
3 changed files with 28 additions and 14 deletions
+6 -4
View File
@@ -2,10 +2,12 @@ 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. Runs before the
// layout renders; auth is bootstrapped by the root +layout.ts, so user.value is
// either a settled User object or null.
export const load: LayoutLoad = () => {
// 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, '/');
}