From af8bb9bcb052b0b5f31d7807b3d414096fd3c40e Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Sat, 29 Nov 2025 06:06:47 +0100 Subject: [PATCH] fix(wisekeep): improve auth flow and redirect handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix login redirect to use /dashboard instead of / - Simplify protected layout auth check with proper error handling - Use static import and onMount for root page auth check - Ensure isChecking is always set to false to prevent loader stuck 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../web/src/routes/(auth)/login/+page.svelte | 2 +- .../web/src/routes/(protected)/+layout.svelte | 41 ++++++++++--------- .../wisekeep/apps/web/src/routes/+page.svelte | 13 ++---- 3 files changed, 26 insertions(+), 30 deletions(-) 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 @@