fix(manacore-web): fix login redirect flow

- Root +page.svelte: use authStore instead of data.session (always undefined)
  → after email verification auto-sign-in, redirects to /home not /login
- (auth)/+layout.svelte: remove racing $effect, keep only onMount redirect check
  → no more double goto() race condition after login
- login/+page.svelte: successRedirect /dashboard → /home (consistent with root)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-31 19:02:04 +02:00
parent 838b4c13de
commit a0caa1f21d
3 changed files with 10 additions and 19 deletions

View file

@ -8,21 +8,11 @@
let { children }: { children: Snippet } = $props();
let isDark = $derived(theme.isDark);
let hasCheckedAuth = $state(false);
// Check auth status on mount
// If user is already authenticated when visiting auth pages, redirect to home
onMount(async () => {
await authStore.initialize();
hasCheckedAuth = true;
if (authStore.isAuthenticated) {
goto('/dashboard');
}
});
// Also react to auth state changes (e.g., after successful login)
$effect(() => {
if (hasCheckedAuth && authStore.isAuthenticated) {
goto('/dashboard');
goto('/home');
}
});
</script>

View file

@ -38,7 +38,7 @@
onVerifyBackupCode={(code) => authStore.verifyBackupCode(code)}
onSendMagicLink={(email) => authStore.sendMagicLink(email)}
{goto}
successRedirect="/dashboard"
successRedirect="/home"
registerPath="/register"
forgotPasswordPath="/forgot-password"
lightBackground="#f3f4f6"

View file

@ -1,13 +1,14 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { onMount } from 'svelte';
import { authStore } from '$lib/stores/auth.svelte';
let { data } = $props();
$effect(() => {
if (!data.session) {
goto('/login');
} else {
onMount(async () => {
await authStore.initialize();
if (authStore.isAuthenticated) {
goto('/home');
} else {
goto('/login');
}
});
</script>