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