Service Layer medium complexity backendmobile
0
Dependencies
0
Dependents
2
Entities
0
Integrations

Description

Handles the business logic for switching a user's active organizational profile and role context. It updates the session token or context object to reflect the selected profile, triggers a data refresh for organization-specific content, and ensures activity attribution is correctly scoped to the new context. It also validates that the user actually holds the target role before completing the switch.

Feature: Profile Switching

profile-switch-service

Sources & reasoning

Profile Switching is v1.0 per the blueprint [v1.0] marker, aligning with Fase 2 of the roadmap. The need is driven by NHF's multi-association requirement (line 106) requiring unambiguous affiliation to prevent double-reporting, and the platform-wide design decision that Org Admins are surfaced as Coordinators on mobile (line 257), both demanding a context-switch mechanism that does not require re-authentication.

  • **Håndtering av medlemmer i flere lokallag (opptil 5):** Avklare tilhørighet og hindre dobbeltrapportering.
  • **On mobile, an Org Admin is surfaced as a Coordinator** - they use the same mobile experience as coordinators without a separate UI path.

Responsibilities

  • Validate that the requesting user holds the selected profile and role
  • Update the active session context with the new organization and role identifiers
  • Trigger refresh of organization-scoped data after a successful switch
  • Prevent double-reporting by clearing stale context from the previous profile
  • Emit a profile-switched event for downstream modules to react to

Interfaces

getAvailableProfiles(userId: string): Promise<Profile[]>
switchProfile(userId: string, targetProfileId: string): Promise<ActiveProfile>
getActiveProfile(sessionId: string): Promise<ActiveProfile>
validateProfileAccess(userId: string, profileId: string): Promise<boolean>

Related Data Entities (2)

Data entities managed by this component