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