Fix ERR_TOO_MANY_REDIRECTS: hapus public/index.php dan tambah guard untuk prevent redirect loop

This commit is contained in:
mwpn
2025-12-18 11:34:20 +07:00
parent 90d0d1a761
commit 28ddcc71ff
6 changed files with 17 additions and 9 deletions

View File

@@ -40,7 +40,11 @@ async function apiRequest(path, options = {}) {
// Unauthorized → clear token & redirect to login
localStorage.removeItem('token');
localStorage.removeItem('user');
window.location.href = '../index.php';
// Cek apakah sudah di login page untuk menghindari redirect loop
const currentPath = window.location.pathname;
if (!currentPath.includes('index.php')) {
window.location.href = '../index.php';
}
throw new Error('Unauthorized');
}

View File

@@ -75,7 +75,9 @@ async function handleLoginSubmit(event) {
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('login-form');
if (form) {
if (Auth.isAuthenticated()) {
// Cek apakah sudah authenticated dan belum di dashboard untuk menghindari redirect loop
const currentPath = window.location.pathname;
if (Auth.isAuthenticated() && !currentPath.includes('dashboard')) {
window.location.href = 'dashboard.html';
return;
}