From f29fd065b6cce853d145968fe6a4e76256d595b3 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 29 Nov 2025 18:27:05 -0800 Subject: [PATCH] fix auth store init with $effect wrap authStore.initFromServer in $effect to react to data prop --- src/routes/+layout.svelte | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 08850b36..399ea8ad 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -27,21 +27,18 @@ // Store scroll positions for each visited route const scrollPositions = new Map(); - // Initialize auth store from server data immediately on load to ensure - // Authorization headers are available for client-side API calls - // Run immediately, not in effect to avoid timing issues - if (browser) { - if (data?.auth) { + // Initialize auth store from server data when data prop is populated + // Use $effect to ensure we react to when server data is available + $effect(() => { + if (browser && data?.auth) { console.log('[+layout] Initializing authStore with token:', data.auth.accessToken ? 'present' : 'missing') authStore.initFromServer( data.auth.accessToken, data.auth.user, data.auth.expiresAt ) - } else { - console.warn('[+layout] No auth data available to initialize authStore') } - } + }) // Save scroll position before navigating away and close sidebar beforeNavigate(({ from }) => {