Fix redirect loop: tambah sessionStorage guard dan path check yang lebih ketat
This commit is contained in:
@@ -40,9 +40,11 @@ async function apiRequest(path, options = {}) {
|
||||
// Unauthorized → clear token & redirect to login
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
sessionStorage.removeItem('auth_redirect_done');
|
||||
// Cek apakah sudah di login page untuk menghindari redirect loop
|
||||
const currentPath = window.location.pathname;
|
||||
if (!currentPath.includes('index.php')) {
|
||||
const isLoginPage = currentPath.includes('index.php');
|
||||
if (!isLoginPage) {
|
||||
window.location.href = '../index.php';
|
||||
}
|
||||
throw new Error('Unauthorized');
|
||||
|
||||
Reference in New Issue
Block a user