authMessageFor function
A readable message for a Firebase Auth error.
Implementation
String authMessageFor(Object error) {
if (error is AuthFailure) return error.message;
if (error is StateError) return error.message;
if (error is! FirebaseAuthException) return '$error';
return switch (error.code) {
'invalid-credential' || 'wrong-password' || 'user-not-found' || 'INVALID_LOGIN_CREDENTIALS' =>
'Wrong email or password.',
'email-already-in-use' => 'An account already exists for that email.',
'weak-password' => 'Password must be at least 6 characters.',
'invalid-email' => 'That email address is not valid.',
'missing-password' => 'Enter your password.',
'user-disabled' => 'This account has been disabled.',
'too-many-requests' => 'Too many attempts. Try again later.',
'network-request-failed' => 'Network error. Check your connection.',
'requires-recent-login' => 'Sign in again, then try this again.',
_ => error.message ?? error.code,
};
}