Fix redirect loop: hapus auto-redirect di index.php, hanya redirect setelah login berhasil

This commit is contained in:
mwpn
2025-12-18 11:41:47 +07:00
parent ef51cf96a2
commit da151681e1
4 changed files with 7 additions and 43 deletions

View File

@@ -73,23 +73,11 @@ async function handleLoginSubmit(event) {
}
// Attach events on login page only
// Hapus auto-redirect untuk mencegah redirect loop
// Redirect hanya setelah login berhasil (di handleLoginSubmit)
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;
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);
}
});