diff --git a/apps/wisekeep/apps/web/src/routes/(auth)/login/+page.svelte b/apps/wisekeep/apps/web/src/routes/(auth)/login/+page.svelte index ce1106f31..fbd1d4577 100644 --- a/apps/wisekeep/apps/web/src/routes/(auth)/login/+page.svelte +++ b/apps/wisekeep/apps/web/src/routes/(auth)/login/+page.svelte @@ -7,7 +7,7 @@ import AppSlider from '$lib/components/AppSlider.svelte'; // Get redirect URL from query params - const redirectTo = $derived($page.url.searchParams.get('redirectTo') || '/'); + const redirectTo = $derived($page.url.searchParams.get('redirectTo') || '/dashboard'); // German translations const translations = { diff --git a/apps/wisekeep/apps/web/src/routes/(protected)/+layout.svelte b/apps/wisekeep/apps/web/src/routes/(protected)/+layout.svelte index 1c6a73a05..34ba978f2 100644 --- a/apps/wisekeep/apps/web/src/routes/(protected)/+layout.svelte +++ b/apps/wisekeep/apps/web/src/routes/(protected)/+layout.svelte @@ -11,31 +11,32 @@ let isChecking = $state(true); // Check auth on mount and redirect if not authenticated - onMount(() => { - const init = async () => { - try { - await authStore.initialize(); - } catch (e) { - console.error('Auth init failed:', e); + onMount(async () => { + let shouldRedirect = false; + + try { + await authStore.initialize(); + shouldRedirect = !authStore.isAuthenticated; + + if (!shouldRedirect) { + // Initialize WebSocket after auth check + initWebSocket(); } + } catch (error) { + console.error('Protected layout init error:', error); + shouldRedirect = true; + } - if (!authStore.isAuthenticated) { - const redirectTo = encodeURIComponent(data.pathname || '/dashboard'); - goto(`/login?redirectTo=${redirectTo}`); - return; - } + // Always set isChecking to false + isChecking = false; - // Initialize WebSocket after auth check - initWebSocket(); - isChecking = false; - }; - - init(); + if (shouldRedirect) { + const redirectTo = encodeURIComponent(data.pathname || '/dashboard'); + goto(`/login?redirectTo=${redirectTo}`); + } // Return cleanup function - return () => { - cleanup(); - }; + return () => cleanup(); }); async function handleSignOut() { diff --git a/apps/wisekeep/apps/web/src/routes/+page.svelte b/apps/wisekeep/apps/web/src/routes/+page.svelte index e38b7fdce..b18f2e04d 100644 --- a/apps/wisekeep/apps/web/src/routes/+page.svelte +++ b/apps/wisekeep/apps/web/src/routes/+page.svelte @@ -1,21 +1,16 @@