import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:shuffle/core/config/app_config_provider.dart'; import 'package:shuffle/core/l10n/app_locale.dart'; import 'package:shuffle/core/supabase/supabase_client_provider.dart'; import 'package:shuffle/features/auth/data/asset_common_password_list.dart'; import 'package:shuffle/features/auth/data/supabase_auth_repository.dart'; import 'package:shuffle/features/auth/domain/auth_repository.dart'; import 'package:shuffle/features/auth/domain/auth_status.dart'; import 'package:shuffle/features/auth/domain/registration_input.dart'; import 'package:shuffle/features/auth/domain/validation/common_passwords.dart'; part 'auth_providers.g.dart'; @Riverpod(keepAlive: true) AuthRepository authRepository(Ref ref) { final repository = SupabaseAuthRepository( ref.watch(supabaseClientProvider).auth, ); ref.onDispose(repository.dispose); return repository; } /// Anmeldestatus als Stream (zuerst der aktuelle Wert, dann Änderungen). @Riverpod(keepAlive: true) Stream authStatus(Ref ref) => ref.watch(authRepositoryProvider).watchStatus(); /// Liste häufiger Passwörter. Lazy: lädt erst beim ersten Lesen (Öffnen eines /// Passwortfeldes), nicht beim App-Start. @Riverpod(keepAlive: true) Future commonPasswordList(Ref ref) => const AssetCommonPasswordList().load(); /// Baut die Registrierungseingabe mit `terms_version` aus der [AppConfig] und /// der aktiven Oberflächensprache als `locale` (F5, F6, KTO-11 Kriterium 11). typedef RegistrationInputFactory = RegistrationInput Function({ required String email, required String password, required String displayName, required bool ageConfirmed, required bool termsAccepted, }); @riverpod RegistrationInputFactory registrationInputFactory(Ref ref) { final termsVersion = ref.watch(appConfigProvider).termsVersion; final locale = ref.watch(appLocaleProvider).languageCode; return ({ required email, required password, required displayName, required ageConfirmed, required termsAccepted, }) => RegistrationInput( email: email, password: password, displayName: displayName, ageConfirmed: ageConfirmed, termsAccepted: termsAccepted, termsVersion: termsVersion, locale: locale, ); }