Fix ERR_TOO_MANY_REDIRECTS: hapus public/index.php dan tambah guard untuk prevent redirect loop
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
// Redirect ke login page di root
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user