Shuffle/app/lib/features/auth/presentation/auth_failure_texts.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

38 lines
1.6 KiB
Dart

import 'package:shuffle/core/l10n/l10n.dart';
import 'package:shuffle/features/auth/domain/auth_failure.dart';
/// User-facing text of an [AuthFailure] (Spec #1 § 4.4, texts from
/// `docs/design/auth-screens.md`).
///
/// `emailSendLimited` has no text of its own: screens treat it as success
/// (F12) or convert it to `rateLimited` beforehand.
String authFailureMessage(AppLocalizations l10n, AuthFailure failure) =>
switch (failure) {
InvalidCredentials() => l10n.authErrorInvalidCredentials,
EmailNotConfirmed() => l10n.authErrorEmailNotConfirmed,
EmailSendLimited() || RateLimited() => l10n.authErrorRateLimited,
WeakPassword(:final reasons) => weakPasswordMessage(l10n, reasons),
SamePassword() => l10n.authErrorSamePassword,
LinkInvalidOrExpired() => l10n.authErrorLinkInvalidOrExpired,
InvalidEmail() => l10n.authErrorEmailInvalid,
RegistrationRejected() => l10n.authErrorRegistrationRejected,
NetworkFailure() => l10n.authErrorNetwork,
Unexpected() => l10n.authErrorUnexpected,
};
/// One sentence per distinct reason; an empty list gets the generic text.
String weakPasswordMessage(
AppLocalizations l10n,
List<WeakPasswordReason> reasons,
) {
final texts = <String>{
for (final reason in reasons)
switch (reason) {
WeakPasswordReason.length => l10n.authErrorWeakPasswordLength,
WeakPasswordReason.pwned => l10n.authErrorWeakPasswordPwned,
WeakPasswordReason.characters ||
WeakPasswordReason.unknown => l10n.authErrorWeakPasswordCharacters,
},
};
return texts.isEmpty ? l10n.authErrorWeakPasswordCharacters : texts.join(' ');
}