fix: wait for auth refresh check before redirecting to login
The $: reactive statement was firing before onMount's tryRefresh() completed, immediately redirecting to /login on every page refresh. Added authChecked flag to gate the redirect logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,15 +8,17 @@
|
||||
import '../app.css';
|
||||
|
||||
const PUBLIC_PATHS = ['/login', '/setup'];
|
||||
let authChecked = false;
|
||||
|
||||
onMount(async () => {
|
||||
if (!$isAuthenticated) {
|
||||
await tryRefresh();
|
||||
}
|
||||
authChecked = true;
|
||||
});
|
||||
|
||||
$: {
|
||||
if (browser && !$isAuthenticated && !PUBLIC_PATHS.some(p => $page.url.pathname.startsWith(p))) {
|
||||
if (browser && authChecked && !$isAuthenticated && !PUBLIC_PATHS.some(p => $page.url.pathname.startsWith(p))) {
|
||||
goto('/login');
|
||||
}
|
||||
}
|
||||
@@ -32,7 +34,11 @@
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
|
||||
{#if $isAuthenticated || PUBLIC_PATHS.some(p => $page.url.pathname.startsWith(p))}
|
||||
{#if !authChecked}
|
||||
<div class="min-h-screen flex items-center justify-center">
|
||||
<p class="text-[var(--text-dim)]">로딩 중...</p>
|
||||
</div>
|
||||
{:else if $isAuthenticated || PUBLIC_PATHS.some(p => $page.url.pathname.startsWith(p))}
|
||||
<slot />
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user