shifsts bug
This commit is contained in:
@@ -11,26 +11,31 @@ export async function checkAuth() {
|
||||
// Check if user has expired
|
||||
if (data.expired) {
|
||||
showStatus('Account has expired. Please contact an administrator.', 'error');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/login.html?expired=true';
|
||||
}, 2000);
|
||||
// Immediate redirect for expired users
|
||||
window.location.href = '/login.html?expired=true';
|
||||
throw new Error('Account expired');
|
||||
}
|
||||
|
||||
if (!data.authenticated) {
|
||||
// Immediate redirect for unauthenticated users
|
||||
window.location.href = '/login.html';
|
||||
throw new Error('Not authenticated');
|
||||
}
|
||||
|
||||
currentUser = data.user;
|
||||
currentUser.userType = data.user.userType || 'user'; // Ensure userType is set
|
||||
|
||||
// Authentication successful - show the app
|
||||
document.body.classList.remove('authenticating');
|
||||
document.body.classList.add('authenticated');
|
||||
document.getElementById('app').classList.remove('app-hidden');
|
||||
|
||||
updateUserInterface();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Auth check failed:', error);
|
||||
if (error.message !== 'Account expired') {
|
||||
window.location.href = '/login.html';
|
||||
}
|
||||
// Always redirect immediately on any auth failure
|
||||
window.location.href = '/login.html';
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Main application entry point
|
||||
import { CONFIG, loadDomainConfig } from './config.js';
|
||||
import { hideLoading, showStatus, setViewportDimensions } from './utils.js';
|
||||
import { hideLoading, showStatus, setViewportDimensions, updateLoadingMessage } from './utils.js';
|
||||
import { checkAuth } from './auth.js';
|
||||
import { initializeMap, getMap } from './map-manager.js';
|
||||
import { loadLocations } from './location-manager.js';
|
||||
@@ -23,28 +23,36 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
setTimeout(setViewportDimensions, 100);
|
||||
});
|
||||
|
||||
console.log('DOM loaded, initializing application...');
|
||||
console.log('DOM loaded, checking authentication...');
|
||||
|
||||
try {
|
||||
// Load domain configuration first
|
||||
updateLoadingMessage('Loading configuration...');
|
||||
await loadDomainConfig();
|
||||
|
||||
// First check authentication
|
||||
// CRITICAL: Check authentication FIRST before any UI initialization
|
||||
// This prevents the map from briefly showing before redirect
|
||||
updateLoadingMessage('Authenticating...');
|
||||
await checkAuth();
|
||||
|
||||
console.log('Authentication confirmed, initializing application...');
|
||||
|
||||
// Setup temp user security measures after authentication
|
||||
setupTempUserSecurity();
|
||||
|
||||
// Then initialize the map
|
||||
updateLoadingMessage('Initializing map...');
|
||||
await initializeMap();
|
||||
|
||||
// Initialize cut manager after map is ready
|
||||
updateLoadingMessage('Loading map overlays...');
|
||||
await cutManager.initialize(getMap());
|
||||
|
||||
// Initialize cut controls for public map
|
||||
await initializeCutControls();
|
||||
|
||||
// Only load locations after map is ready
|
||||
updateLoadingMessage('Loading locations...');
|
||||
await loadLocations();
|
||||
|
||||
// Setup other features
|
||||
@@ -52,13 +60,24 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
setupAutoRefresh();
|
||||
|
||||
// Initialize Unified Search
|
||||
updateLoadingMessage('Setting up search...');
|
||||
await initializeUnifiedSearch();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Initialization error:', error);
|
||||
showStatus('Failed to initialize application', 'error');
|
||||
// If authentication fails, we should already be redirected
|
||||
// But in case of other errors, clean up the loading state
|
||||
if (!error.message.includes('Not authenticated') && !error.message.includes('Account expired')) {
|
||||
document.body.classList.remove('authenticating');
|
||||
document.body.classList.add('authenticated');
|
||||
document.getElementById('app').classList.remove('app-hidden');
|
||||
showStatus('Failed to initialize application', 'error');
|
||||
}
|
||||
} finally {
|
||||
hideLoading();
|
||||
// Only hide loading if we're not being redirected for authentication
|
||||
if (!document.body.classList.contains('authenticating')) {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -52,6 +52,13 @@ export function hideLoading() {
|
||||
}
|
||||
}
|
||||
|
||||
export function updateLoadingMessage(message) {
|
||||
const loadingElement = document.querySelector('#loading p');
|
||||
if (loadingElement) {
|
||||
loadingElement.textContent = message;
|
||||
}
|
||||
}
|
||||
|
||||
export function updateLocationCount(count) {
|
||||
const countElement = document.getElementById('location-count');
|
||||
const mobileCountElement = document.getElementById('mobile-location-count');
|
||||
|
||||
Reference in New Issue
Block a user