Bugfix: Why did the admin sidebar show 'GUEST' role and Space Manage...

Documentation for Sessions

🐛 Bugfix: Why did the admin sidebar show 'GUEST' role and Space Manage...

Date: 2026-02-11
Time: 12:54:53 UTC
Session: gspace1-105.6
Agent: backend
Confidence: 97%
Status: ✅ Documented


📋 Decision Context

Question:

Why did the admin sidebar show 'GUEST' role and Space Management show empty?

Task: Session 105: Fix GUEST role and empty Space/User Management


🎯 Decision Made

Chosen:

Two root causes: (1) Backend sends roles:string[] but auth-ui User expects role:string. Fixed by normalizing in setAuthState(). (2) Space Management called GET /api/spaces/me which returns ONE space for current user, not all spaces. Created GET /api/admin/spaces and /api/admin/users endpoints that query MongoDB directly for full platform listing.

Options Considered:

  1. Normalize role in auth-ui setAuthState (chosen)
  2. Change backend to send both role and roles
  3. Change auth-ui User type to use roles array

💭 Reasoning

The backend BackendAuthService.toUserProfile() returns {roles: ['developer']} but the auth-ui User interface expects {role: 'developer'}. The auth-ui userRole computed defaults to 'guest' when role is undefined. For spaces/users, the existing endpoints are scoped to a single user's data. Admin views need platform-wide listing which requires direct MongoDB queries. Added both to the AdminStatsService since it already has the connection.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation