Auth Provider Wiring
Riverpod NotifierProviders for the auth feature
Overview
There is no GetIt — every auth dependency is a Riverpod Provider declared next to its notifier. authApiServiceProvider and authStorageServiceProvider are the two leaf providers; the notifiers compose them in their build() methods.
User Flow
- authApiServiceProvider exposes a singleton AuthApiService (wraps Dio).
- authStorageServiceProvider exposes AuthStorageService (wraps SharedPreferences).
- loginNotifierProvider, registerNotifierProvider, forgotPasswordProvider, changePasswordProvider — each ref.read the two leaf providers in build().
- authStateProvider (StateNotifierProvider, legacy API) exposes the global AuthState consumed app-wide.
- userRoleProvider (defined in user_role.dart) is the third global the auth feature mutates — switchRole / setRole / saveUserRole.
Cases & Edge Cases
- authStateProvider uses the legacy StateNotifierProvider (flutter_riverpod/legacy.dart) while all per-feature notifiers use the modern NotifierProvider — both coexist on Riverpod 3.x.
- build() is called once per notifier lifecycle; ref.read inside build is safe but ref.watch would create a rebuild loop.
- Apple/Google SDKs are constructed lazily inside the notifier methods (not in DI) so dotenv must be loaded first — main.dart guarantees ordering.
Code References
- lib/src/features/shared/auth/login/presentation/providers/auth/login_provider.dart:411 // authApiServiceProvider
- lib/src/features/shared/auth/login/presentation/providers/auth/login_provider.dart:415 // authStorageServiceProvider
- lib/src/features/shared/auth/login/presentation/providers/auth/login_provider.dart:419 // loginNotifierProvider
- lib/src/core/services/auth_storage.dart:257 // authStateProvider
- lib/src/core/services/user_role.dart
API Calls
Empty — fill this in later. Open the manifest and add content here.
Notes
The two leaf providers are duplicated as plain class instantiations elsewhere (e.g. NotificationService also constructs AuthStorageService directly) — Riverpod is the canonical wiring but not strictly enforced.