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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user