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

@@ -70,10 +70,26 @@
// Jika sudah login, langsung arahkan ke dashboard utama (public/dashboard)
// Cek dulu apakah kita sudah di dashboard untuk menghindari redirect loop
const currentPath = window.location.pathname;
if (Auth.isAuthenticated() && !currentPath.includes('dashboard.html')) {
window.location.href = 'public/dashboard/dashboard.html';
}
// Gunakan check yang lebih spesifik untuk mencegah loop
(function() {
// Cek apakah ini benar-benar halaman index.php (bukan dashboard)
const currentPath = window.location.pathname;
const isIndexPage = currentPath.endsWith('index.php') || currentPath.endsWith('/') || currentPath === '/';
const isDashboardPage = currentPath.includes('dashboard.html') || currentPath.includes('event.html') || currentPath.includes('settings.html');
// Hanya redirect jika:
// 1. User sudah authenticated
// 2. Kita di index page (bukan dashboard)
// 3. Belum pernah redirect (cek sessionStorage)
if (Auth.isAuthenticated() && isIndexPage && !isDashboardPage) {
const redirectKey = 'auth_redirect_done';
if (!sessionStorage.getItem(redirectKey)) {
sessionStorage.setItem(redirectKey, '1');
window.location.href = 'public/dashboard/dashboard.html';
return;
}
}
})();
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();