Service Layer high complexity mobile
0
Dependencies
0
Dependents
4
Entities
0
Integrations

Description

A Riverpod StateNotifier that owns the currently active role-organization pair for the authenticated user. Persists the selected context to Drift local storage so it survives app restarts, and injects the active organization ID into ApiHttpClient as a request header on every API call to enforce tenant scoping.

Feature: Profile Switching

profile-context-service

Sources & reasoning

This is the core state-management component for the feature. It covers persistence, provider lifecycle management, and security (tenant header injection). Without it the context switch has no durable state, providers would not be invalidated, and cross-org data leakage becomes possible.

No source references — this artifact was included based on reasoning alone (see above).

Responsibilities

  • Maintain the active role-org pair as observable Riverpod state
  • Persist the selected context to Drift so it survives restarts
  • On context switch, invalidate all organization-scoped Riverpod providers
  • Inject the active organization ID as a header in ApiHttpClient for every outgoing request
  • Expose the list of available role-org pairs from user_organization_roles for the switch widget

Interfaces

switchContext(roleOrgPair: RoleOrgPair): Future<void>
getActiveContext(): RoleOrgPair
watchActiveContext(): Stream<RoleOrgPair>
getAvailableContexts(): Future<List<RoleOrgPair>>
restorePersistedContext(): Future<void>