Stu Mason
Stu Mason

Activity

StuMason/cleanconnect
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

  • /dashboard redirects based on first matching role (cleaner takes priority)
  • Sidebar and header nav links use is_cleaner boolean to determine dashboard URL
  • No way for multi-role users to switch between their different role views

Proposed Solution

  1. Active Role Session State: Store the user's currently active role in the session
  2. Role Switcher UI: Add a dropdown/toggle in the navigation for users with multiple roles to switch between them
  3. Role-Aware Routing: Update the dashboard redirect and navigation to respect the active role from session

Implementation Notes

  • The User model already has a getActiveProfile() method that reads from session('active_role')
  • Need to create an endpoint to switch active role: POST /switch-role
  • Update HandleInertiaRequests to share active_role with 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 endpoint
  • app/Http/Middleware/HandleInertiaRequests.php - Share active role
  • resources/js/components/app-sidebar.tsx - Role switcher UI
  • resources/js/components/app-header.tsx - Role switcher UI
  • resources/js/components/nav-user.tsx - Potential location for role switcher

Priority

Medium - Current implementation works for single-role users (the majority case)

  • Current fix in place redirects /dashboard to role-specific dashboards
  • Sidebar/header now use role-aware navigation