Fix: perbaiki logout button handler dan path detection untuk konsistensi lokal dan produksi

This commit is contained in:
mwpn
2025-12-19 05:52:09 +07:00
parent de79ba0af2
commit 8447b05e90
3 changed files with 66 additions and 8 deletions

View File

@@ -20,10 +20,33 @@ export const Auth = {
},
logout() {
console.log('[Auth] Logout called');
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
sessionStorage.removeItem('auth_redirect_done');
window.location.href = '../index.html';
// Deteksi path yang benar untuk redirect
const currentPath = window.location.pathname;
let loginPath = '../index.html';
// Jika di dashboard/, gunakan ../index.html
// Jika di root, gunakan index.html
if (currentPath.includes('/dashboard/')) {
loginPath = '../index.html';
} else if (currentPath.endsWith('/') || currentPath === '/') {
loginPath = 'index.html';
} else {
// Fallback: coba detect dari current path
const pathParts = currentPath.split('/').filter(p => p);
if (pathParts.length > 0 && pathParts[pathParts.length - 1].includes('dashboard')) {
loginPath = '../index.html';
} else {
loginPath = 'index.html';
}
}
console.log('[Auth] Redirecting to:', loginPath, 'from:', currentPath);
window.location.href = loginPath;
}
};