fix(wisekeep): improve auth flow and redirect handling

- 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 <noreply@anthropic.com>
This commit is contained in:
Till-JS 2025-11-29 06:06:47 +01:00
parent 8b61399a64
commit af8bb9bcb0
3 changed files with 26 additions and 30 deletions

View file

@ -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 = {

View file

@ -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() {

View file

@ -1,21 +1,16 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { browser } from '$app/environment';
import { onMount } from 'svelte';
import { authStore } from '$lib/stores/auth.svelte';
async function checkAuthAndRedirect() {
const { authStore } = await import('$lib/stores/auth.svelte');
onMount(async () => {
await authStore.initialize();
if (authStore.isAuthenticated) {
goto('/dashboard', { replaceState: true });
} else {
goto('/login', { replaceState: true });
}
}
if (browser) {
checkAuthAndRedirect();
}
});
</script>
<svelte:head>