Register providers in Riverpod dependency graph
epic-role-based-access-control-data-infrastructure-task-007 — Register SupabaseRoleProvider and RoleRepository as Riverpod providers so they are injectable across the app. Use a ref-scoped provider for SupabaseRoleProvider and a ChangeNotifierProvider or Provider for RoleRepository. Ensure the Supabase client dependency is correctly injected via the existing supabase-client-provider pattern used elsewhere in the project.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
Follow the exact provider naming and file placement convention already used in the project for other data layer providers (e.g., document_providers.dart, activity_providers.dart). Use `Provider
Do not use `keepAlive: true` unless the repository must survive all widget tree rebuilds — check existing patterns first.
Testing Requirements
Unit tests: use ProviderContainer with overrides to inject a mock SupabaseRoleProvider and verify RoleRepository receives it correctly. Verify that reading roleRepositoryProvider twice from the same ProviderContainer returns the same instance (singleton behavior). Integration test: boot a ProviderScope with real providers against a local Supabase instance and confirm RoleRepository.fetchRolesForUser() resolves without error. Verify that overriding supabaseRoleProviderProvider in a ProviderScope correctly replaces the implementation in RoleRepository (essential for test isolation).
The get_my_roles RPC call adds a network round-trip immediately after login, potentially increasing the time before the home screen renders. If Supabase RPC is slow or the roles table lacks proper indexing, users with multiple org affiliations could experience noticeable delays.
Mitigation & Contingency
Mitigation: Index user_roles on user_id and org_unit_id. Use JWT claim extraction as the primary fast path; fall back to the RPC only when claims are absent or stale. Set a 3-second timeout with a fallback to cached roles.
Contingency: If RPC latency exceeds acceptable thresholds in production, pre-fetch and embed roles into the session JWT at login time via a Supabase Auth hook, eliminating the post-login RPC entirely.
Users who belong to multiple organizations (e.g., a coordinator in one NHF chapter who is also a peer mentor in another) may have conflicting role assignments. The repository layer must correctly scope roles to the active organization context set during the organization selection step, or it could return roles from the wrong org.
Mitigation & Contingency
Mitigation: Always filter role queries by the active org_unit_id stored in the tenant session. Write integration tests that simulate multi-org users and verify only the correct org's roles are returned.
Contingency: If org-scoping logic is found to be incorrect during QA, add an explicit org_unit_id parameter to get_my_roles RPC and require the client to always pass the active org context, making the scoping explicit rather than inferred.