From 437b0c7516c00b85ad816aefd3180983130f2528 Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Sun, 16 Nov 2025 19:16:07 +0000 Subject: [PATCH] Phase 0: Fix AppSidebar to only load module settings when authenticated - Added isAuthenticated check before loading module enable settings - Prevents 403 errors when user is not logged in - Only loads settings when user is authenticated and settings aren't already loaded --- frontend/src/layout/AppSidebar.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/layout/AppSidebar.tsx b/frontend/src/layout/AppSidebar.tsx index 4f9c2b9e..fe1c2825 100644 --- a/frontend/src/layout/AppSidebar.tsx +++ b/frontend/src/layout/AppSidebar.tsx @@ -38,7 +38,7 @@ type MenuSection = { const AppSidebar: React.FC = () => { const { isExpanded, isMobileOpen, isHovered, setIsHovered } = useSidebar(); const location = useLocation(); - const { user } = useAuthStore(); + const { user, isAuthenticated } = useAuthStore(); const { moduleEnableSettings, isModuleEnabled: checkModuleEnabled, loadModuleEnableSettings, loading: settingsLoading } = useSettingsStore(); // Show admin menu only for users in aws-admin account @@ -67,14 +67,15 @@ const AppSidebar: React.FC = () => { [location.pathname] ); - // Load module enable settings on mount (only once) + // Load module enable settings on mount (only once) - but only if user is authenticated useEffect(() => { - if (!moduleEnableSettings && !settingsLoading) { + // Only load if user is authenticated and settings aren't already loaded + if (user && isAuthenticated && !moduleEnableSettings && !settingsLoading) { loadModuleEnableSettings().catch((error) => { console.warn('Failed to load module enable settings:', error); }); } - }, []); // Empty dependency array - only run on mount + }, [user, isAuthenticated]); // Only run when user/auth state changes // Define menu sections with useMemo to prevent recreation on every render // Filter out disabled modules based on module enable settings