Role Switch Clears Navigation Stack to Prevent Stale UI State
When a user switches their active role via the Role Switch Widget, the Role Authorization Service triggers a full navigation reset after re-evaluating the new role's permissions. This clears all navigation history, closes any open modals or bottom sheets, and navigates the user to the appropriate home screen for the new role. This prevents scenarios where a coordinator who was viewing a peer mentor's activity list switches roles but the old screen remains visible, potentially causing them to take actions in the wrong organizational context. The navigation reset is implemented via Flutter's GoRouter stack clearing mechanism and is applied regardless of the user's current position in the app.
User Story
Acceptance Criteria
- Given a user switches roles via the Role Switch Widget, when the role switch completes, then the navigation stack is fully cleared and the user lands on the home screen for the new role
- Given a user was viewing a restricted screen under their previous role, when they switch to a different role, then the previous screen is not visible and back navigation does not return to it
- Given a user was mid-way through a multi-step workflow such as an activity wizard when they initiated a role switch, when the switch completes, then the workflow is abandoned and the user is on the new role's home screen
- Given the navigation reset has occurred, when the user presses the back button on the new home screen, then they are not navigated back to any screen from their previous role context
- Given the role switch and navigation reset complete, when the user views the role switch widget, then it displays the newly active role name
Business Value
Coordinators frequently switch between their coordinator role and peer mentor views during a working session. Without a full navigation reset, they risk performing actions such as submitting registrations, approving expenses, or modifying contacts in the wrong role context, which would corrupt organizational data and potentially cause Bufdir reporting errors. The navigation reset aligns UI state with access control state at all times, acting as a key data integrity safeguard.
Components
- Role Switch Widget ui
- Role Authorization Service service
- Permission Guard service
- Role Config Store data