diff --git a/frontend/src/layout/AppLayout.tsx b/frontend/src/layout/AppLayout.tsx index f2b6fbbc..1483e847 100644 --- a/frontend/src/layout/AppLayout.tsx +++ b/frontend/src/layout/AppLayout.tsx @@ -24,8 +24,11 @@ const LayoutContent: React.FC = () => { const [debugEnabled, setDebugEnabled] = useState(false); const lastUserRefresh = useRef(0); - // Initialize site store on mount - only once + // Initialize site store on mount - only once, but only if authenticated useEffect(() => { + // Only load sites if user is authenticated + if (!isAuthenticated) return; + if (!hasLoadedSite.current && !isLoadingSite.current) { hasLoadedSite.current = true; isLoadingSite.current = true; @@ -44,8 +47,11 @@ const LayoutContent: React.FC = () => { loadActiveSite() .catch((error) => { - console.error('AppLayout: Error loading active site:', error); - addError(error, 'AppLayout.loadActiveSite'); + // Don't log 403 errors as they're expected when not authenticated + if (error.status !== 403) { + console.error('AppLayout: Error loading active site:', error); + addError(error, 'AppLayout.loadActiveSite'); + } }) .finally(() => { clearTimeout(timeoutId); @@ -53,7 +59,7 @@ const LayoutContent: React.FC = () => { isLoadingSite.current = false; }); } - }, []); // Empty deps - only run once on mount + }, [isAuthenticated]); // Run when authentication state changes // Load sectors when active site changes (by ID, not object reference) useEffect(() => {