Client SaaS
TypeScript
Issue Resolved
Issue #20 closed: Add role switching for users with multiple roles
Problem
Currently, when a user has multiple roles (e.g., both cleaner and client, or admin), the dashboard routing and navigation use simple is_cleaner checks which doesn't account for users wanting to switch between roles.
Current Behavior
/dashboardredirects based on first matching role (cleaner takes priority)- Sidebar and header nav links use
is_cleanerboolean to determine dashboard URL - No way for multi-role users to switch between their different role views
Proposed Solution
- Active Role Session State: Store the user's currently active role in the session
- Role Switcher UI: Add a dropdown/toggle in the navigation for users with multiple roles to switch between them
- Role-Aware Routing: Update the dashboard redirect and navigation to respect the active role from session
Implementation Notes
- The
Usermodel already has agetActiveProfile()method that reads fromsession('active_role') - Need to create an endpoint to switch active role:
POST /switch-role - Update
HandleInertiaRequeststo shareactive_rolewith frontend - Add role switcher component to sidebar/header when user has 2+ roles
- Navigation items should reflect the active role, not just check
is_cleaner
Files to Update
routes/web.php- Add role switching endpointapp/Http/Middleware/HandleInertiaRequests.php- Share active roleresources/js/components/app-sidebar.tsx- Role switcher UIresources/js/components/app-header.tsx- Role switcher UIresources/js/components/nav-user.tsx- Potential location for role switcher
Priority
Medium - Current implementation works for single-role users (the majority case)
Related
- Current fix in place redirects
/dashboardto role-specific dashboards - Sidebar/header now use role-aware navigation