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
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-16 19:16:07 +00:00
parent 4de9128430
commit 437b0c7516

View File

@@ -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