Fix: perbaiki logout button handler dan path detection untuk konsistensi lokal dan produksi
This commit is contained in:
@@ -173,9 +173,27 @@
|
|||||||
import './js/dashboard.js';
|
import './js/dashboard.js';
|
||||||
import './js/realtime.js';
|
import './js/realtime.js';
|
||||||
|
|
||||||
document.getElementById('logout-button')?.addEventListener('click', () => {
|
// Setup logout button - pastikan ter-attach dengan benar
|
||||||
Auth.logout();
|
function setupLogoutButton() {
|
||||||
});
|
const logoutBtn = document.getElementById('logout-button');
|
||||||
|
if (logoutBtn) {
|
||||||
|
console.log('[Dashboard] Logout button found, attaching event listener');
|
||||||
|
logoutBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log('[Dashboard] Logout button clicked');
|
||||||
|
Auth.logout();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('[Dashboard] Logout button not found!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup saat DOM ready
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', setupLogoutButton);
|
||||||
|
} else {
|
||||||
|
setupLogoutButton();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -248,10 +248,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout handler
|
// Logout handler - pastikan ter-attach dengan benar
|
||||||
document.getElementById('logout-button')?.addEventListener('click', () => {
|
function setupLogoutButton() {
|
||||||
Auth.logout();
|
const logoutBtn = document.getElementById('logout-button');
|
||||||
});
|
if (logoutBtn) {
|
||||||
|
console.log('[Events] Logout button found, attaching event listener');
|
||||||
|
logoutBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log('[Events] Logout button clicked');
|
||||||
|
Auth.logout();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('[Events] Logout button not found!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup saat DOM ready
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', setupLogoutButton);
|
||||||
|
} else {
|
||||||
|
setupLogoutButton();
|
||||||
|
}
|
||||||
|
|
||||||
// Video HLS setup - menggunakan URL kamera dari database
|
// Video HLS setup - menggunakan URL kamera dari database
|
||||||
let gatesCache = {}; // Cache untuk gates dengan camera URL
|
let gatesCache = {}; // Cache untuk gates dengan camera URL
|
||||||
|
|||||||
@@ -20,10 +20,33 @@ export const Auth = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
|
console.log('[Auth] Logout called');
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
localStorage.removeItem(USER_KEY);
|
localStorage.removeItem(USER_KEY);
|
||||||
sessionStorage.removeItem('auth_redirect_done');
|
sessionStorage.removeItem('auth_redirect_done');
|
||||||
window.location.href = '../index.html';
|
|
||||||
|
// Deteksi path yang benar untuk redirect
|
||||||
|
const currentPath = window.location.pathname;
|
||||||
|
let loginPath = '../index.html';
|
||||||
|
|
||||||
|
// Jika di dashboard/, gunakan ../index.html
|
||||||
|
// Jika di root, gunakan index.html
|
||||||
|
if (currentPath.includes('/dashboard/')) {
|
||||||
|
loginPath = '../index.html';
|
||||||
|
} else if (currentPath.endsWith('/') || currentPath === '/') {
|
||||||
|
loginPath = 'index.html';
|
||||||
|
} else {
|
||||||
|
// Fallback: coba detect dari current path
|
||||||
|
const pathParts = currentPath.split('/').filter(p => p);
|
||||||
|
if (pathParts.length > 0 && pathParts[pathParts.length - 1].includes('dashboard')) {
|
||||||
|
loginPath = '../index.html';
|
||||||
|
} else {
|
||||||
|
loginPath = 'index.html';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[Auth] Redirecting to:', loginPath, 'from:', currentPath);
|
||||||
|
window.location.href = loginPath;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user