Fix: perbaiki logout button handler dan path detection untuk konsistensi lokal dan produksi
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user