Fix redirect loop: tambah sessionStorage guard dan path check yang lebih ketat
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user