fix menu tax in data and fix session when multiple user login

This commit is contained in:
arifal hidayat
2025-08-07 00:51:46 +07:00
parent 0abf278aa3
commit af05a39a82
13 changed files with 1209 additions and 36 deletions

View File

@@ -171,16 +171,23 @@ class ApiTokenManager {
try {
const response = await fetch(url, mergedOptions);
// If unauthorized, try to generate new token
if (response.status === 401 && this.hasToken()) {
console.log('Token expired, generating new token...');
const newToken = await this.generateToken();
if (newToken) {
// Retry request with new token
mergedOptions.headers.Authorization = `Bearer ${newToken}`;
return fetch(url, mergedOptions);
// If unauthorized, check if it's a session issue
if (response.status === 401) {
if (this.hasToken()) {
console.log('Token expired, generating new token...');
const newToken = await this.generateToken();
if (newToken) {
// Retry request with new token
mergedOptions.headers.Authorization = `Bearer ${newToken}`;
return fetch(url, mergedOptions);
}
}
// If still 401, it might be a session issue
console.log('Session invalid, redirecting to login...');
this.handleSessionInvalid();
return response;
}
return response;
@@ -189,6 +196,33 @@ class ApiTokenManager {
throw error;
}
}
handleSessionInvalid() {
// Show notification
this.showNotification('Session Anda telah berakhir. Silakan login ulang.', 'warning');
// Redirect to login after 3 seconds
setTimeout(() => {
window.location.href = '/login';
}, 3000);
}
showNotification(message, type = 'info') {
// Check if notification library exists
if (typeof toastr !== 'undefined') {
toastr[type](message);
} else if (typeof Swal !== 'undefined') {
Swal.fire({
title: 'Peringatan',
text: message,
icon: type,
confirmButtonText: 'OK'
});
} else {
// Fallback to alert
alert(message);
}
}
}
// Export singleton instance