Shuffle/app/lib/features/auth/presentation/providers/auth_providers.dart
cschlaefke e632da2344 feat(auth): add registration, check-email and email-link screens
Implements KTO-01 criteria 1-4, 10 and 11 (client part).

Refs #1

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:27:16 +01:00

67 lines
2.5 KiB
Dart

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> authStatus(Ref ref) =>
ref.watch(authRepositoryProvider).watchStatus();
Duration? _noRetry(int retryCount, Object error) => null;
/// Liste häufiger Passwörter. Lazy: lädt erst beim ersten Lesen (Öffnen eines
/// Passwortfeldes), nicht beim App-Start. Ohne automatische Wiederholung:
/// Schlägt das Laden fehl, prüft der Client nur die Länge (der Server
/// erzwingt sie ebenfalls), statt das Absenden zu blockieren.
@Riverpod(keepAlive: true, retry: _noRetry)
Future<CommonPasswordList> 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,
);
}