Service Layer medium complexity mobilebackend
0
Dependencies
0
Dependents
0
Entities
0
Integrations

Description

A service layer responsible for managing the session context switch between organizational profiles without requiring re-authentication. It validates the target profile against RBAC rules and the module toggle registry of the selected organization, then updates the active session context accordingly. It ensures no cross-tenant data leakage occurs during or after the context transition.

Feature: Profile Switching

profile-switch-service

Sources & reasoning

The source doc explicitly lists a "role switch" widget in the shared widget inventory (line 305) and calls out multi-association membership (up to 5 local associations, line 109) as an NHF-specific requirement. The Org Admin-as-Coordinator mobile pattern (line 258) reinforces the need. The blueprint assigns this v1.0, consistent with Fase 2 scope for multi-org handling; MVP covers the single-context case first.

  • docs/source/likeperson.md · line 109
    Håndtering av medlemmer i flere lokallag (opptil 5): Avklare tilhørighet og hindre dobbeltrapportering.
  • docs/source/likeperson.md · line 258
    On mobile, an Org Admin is surfaced as a Coordinator - they use the same mobile experience as coordinators without a separate UI path.
  • docs/source/likeperson.md · line 305
    Reusable widgets: AppButton, AppTextField, bottom nav, page header, role switch, custom fields table

Responsibilities

  • Fetch all available profiles and organizational contexts for the authenticated user
  • Validate that the target profile is permitted under current authentication credentials
  • Update the active session context to reflect the selected organization and role
  • Apply the target organization's module toggle registry and RBAC rules post-switch
  • Emit context-change events so dependent modules (dashboard, navigation) can re-render

Interfaces

getAvailableProfiles(userId: string): Promise<UserProfile[]>
switchProfile(userId: string, targetProfileId: string): Promise<SessionContext>
validateProfileAccess(userId: string, profileId: string): Promise<boolean>
getActiveProfile(sessionId: string): Promise<UserProfile>
notifyContextChanged(context: SessionContext): void