Navbar fixed

This commit is contained in:
2025-11-08 01:27:24 +03:00
parent c1c443401d
commit 75daf05e35

View File

@@ -6,27 +6,40 @@
import { browser } from '$app/environment'; import { browser } from '$app/environment';
let isAuthenticated = false; let isAuthenticated = false;
let isLoginPage = false; let currentPath = '/';
let isLoginPage = true;
// Authentication state'ini kontrol et function updateAuthState() {
function checkAuth() { if (!browser) return;
if (browser) { const storedUser = localStorage.getItem('user');
const user = localStorage.getItem('user'); isAuthenticated = !!storedUser;
isAuthenticated = !!user;
isLoginPage = $page.url.pathname === '/';
}
} }
// Page değiştiğinde ve component mount olduğında kontrol et const handleStorageChange = () => {
updateAuthState();
};
onMount(() => { 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; $: shouldShowNavbar = isAuthenticated && !isLoginPage;
</script> </script>
@@ -66,4 +79,4 @@
min-height: calc(100vh - 70px); min-height: calc(100vh - 70px);
} }
} }
</style> </style>