Fix redirect loop: tambah sessionStorage guard dan path check yang lebih ketat

This commit is contained in:
mwpn
2025-12-18 11:37:54 +07:00
parent d9ab8a1f03
commit 1528559c20
5 changed files with 48 additions and 9 deletions

View File

@@ -76,10 +76,18 @@ document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('login-form');
if (form) {
// Cek apakah sudah authenticated dan belum di dashboard untuk menghindari redirect loop
// Hanya redirect jika benar-benar di login page (bukan dashboard)
const currentPath = window.location.pathname;
if (Auth.isAuthenticated() && !currentPath.includes('dashboard')) {
window.location.href = 'dashboard.html';
return;
const isLoginPage = currentPath.includes('index.php') || (currentPath.endsWith('/') && !currentPath.includes('dashboard'));
const isDashboardPage = currentPath.includes('dashboard.html') || currentPath.includes('event.html') || currentPath.includes('settings.html');
if (Auth.isAuthenticated() && isLoginPage && !isDashboardPage) {
const redirectKey = 'auth_redirect_done';
if (!sessionStorage.getItem(redirectKey)) {
sessionStorage.setItem(redirectKey, '1');
window.location.href = 'dashboard.html';
return;
}
}
form.addEventListener('submit', handleLoginSubmit);
}