some fixes to the auth and lockouts
This commit is contained in:
0
map/app/public/js/admin/auth.js
Normal file
0
map/app/public/js/admin/auth.js
Normal file
0
map/app/public/js/admin/navigation.js
Normal file
0
map/app/public/js/admin/navigation.js
Normal file
0
map/app/public/js/admin/shifts.js
Normal file
0
map/app/public/js/admin/shifts.js
Normal file
0
map/app/public/js/admin/startLocation.js
Normal file
0
map/app/public/js/admin/startLocation.js
Normal file
0
map/app/public/js/admin/users.js
Normal file
0
map/app/public/js/admin/users.js
Normal file
0
map/app/public/js/admin/utils.js
Normal file
0
map/app/public/js/admin/utils.js
Normal file
0
map/app/public/js/admin/walkSheet.js
Normal file
0
map/app/public/js/admin/walkSheet.js
Normal file
@@ -96,6 +96,17 @@ function setupAutoRefresh() {
|
||||
|
||||
refreshInterval = setInterval(async () => {
|
||||
try {
|
||||
// Check if user is still authenticated
|
||||
const authResponse = await fetch('/api/auth/check');
|
||||
const authData = await authResponse.json();
|
||||
|
||||
if (!authData.authenticated) {
|
||||
// Stop auto-refresh if not authenticated
|
||||
clearInterval(refreshInterval);
|
||||
console.log('Auto-refresh stopped - user not authenticated');
|
||||
return;
|
||||
}
|
||||
|
||||
await loadLocations();
|
||||
consecutiveErrors = 0; // Reset error count on success
|
||||
} catch (error) {
|
||||
@@ -111,6 +122,17 @@ function setupAutoRefresh() {
|
||||
const slowInterval = refreshInterval_ms * 2; // Double the interval
|
||||
refreshInterval = setInterval(async () => {
|
||||
try {
|
||||
// Check if user is still authenticated
|
||||
const authResponse = await fetch('/api/auth/check');
|
||||
const authData = await authResponse.json();
|
||||
|
||||
if (!authData.authenticated) {
|
||||
// Stop auto-refresh if not authenticated
|
||||
clearInterval(refreshInterval);
|
||||
console.log('Auto-refresh stopped - user not authenticated');
|
||||
return;
|
||||
}
|
||||
|
||||
await loadLocations();
|
||||
consecutiveErrors = 0;
|
||||
} catch (error) {
|
||||
|
||||
@@ -126,3 +126,16 @@ export function setViewportDimensions() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add session expiry detection
|
||||
function handleAuthError(error) {
|
||||
if (error.status === 401) {
|
||||
// Stop all intervals
|
||||
if (typeof autoRefreshInterval !== 'undefined') {
|
||||
clearInterval(autoRefreshInterval);
|
||||
}
|
||||
|
||||
// Redirect to login with expiry message
|
||||
window.location.href = '/login.html?expired=true';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user