diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d33fd6b..0d0a6da 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -6,27 +6,40 @@ import { browser } from '$app/environment'; let isAuthenticated = false; - let isLoginPage = false; + let currentPath = '/'; + let isLoginPage = true; - // Authentication state'ini kontrol et - function checkAuth() { - if (browser) { - const user = localStorage.getItem('user'); - isAuthenticated = !!user; - isLoginPage = $page.url.pathname === '/'; - } + function updateAuthState() { + if (!browser) return; + const storedUser = localStorage.getItem('user'); + isAuthenticated = !!storedUser; } - // Page değiştiğinde ve component mount olduğında kontrol et + const handleStorageChange = () => { + updateAuthState(); + }; + onMount(() => { - checkAuth(); + updateAuthState(); + if (browser) { + window.addEventListener('storage', handleStorageChange); + } + + return () => { + if (browser) { + window.removeEventListener('storage', handleStorageChange); + } + }; }); $: { - checkAuth(); + currentPath = $page.url.pathname; + isLoginPage = currentPath === '/'; + if (browser) { + updateAuthState(); + } } - // Navbar'ı gösterme kararı $: shouldShowNavbar = isAuthenticated && !isLoginPage; @@ -66,4 +79,4 @@ min-height: calc(100vh - 70px); } } - \ No newline at end of file +