mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 07:39:39 +02:00
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:
parent
838b4c13de
commit
a0caa1f21d
3 changed files with 10 additions and 19 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue