Navbar fixed
This commit is contained in:
@@ -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;
|
||||
</script>
|
||||
|
||||
@@ -66,4 +79,4 @@
|
||||
min-height: calc(100vh - 70px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user