Navbar fixed
This commit is contained in:
@@ -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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user