Open4
Firebase Authのエラーコード

メールアドレス認証でハンドリングが必要なエラーコード

email_auth_exception.dart
import 'package:firebase_auth/firebase_auth.dart';
enum EmailAuthException implements Exception {
emailAlreadyInUse,
invalidEmail,
operationNotAllowed,
weakPassword,
userDisabled,
userNotFound,
wrongPassword;
factory EmailAuthException.from(FirebaseAuthException e) => switch (e.code) {
'email-already-in-use' => EmailAuthException.emailAlreadyInUse,
'invalid-email' => EmailAuthException.invalidEmail,
'operation-not-allowed' => EmailAuthException.operationNotAllowed,
'weak-password' => EmailAuthException.weakPassword,
'user-disabled' => EmailAuthException.userDisabled,
'user-not-found' => EmailAuthException.userNotFound,
'wrong-password' => EmailAuthException.wrongPassword,
_ => throw ArgumentError(e.code),
};
}
extension EmailAuhExceptionReason on EmailAuthException {
String get message => switch (this) {
EmailAuthException.emailAlreadyInUse => 'このメールアドレスは既に使用されています',
EmailAuthException.invalidEmail => 'メールアドレスまたはパスワードが間違っています',
EmailAuthException.operationNotAllowed => 'メール/パスワード認証が無効です',
EmailAuthException.weakPassword => 'パスワードが弱すぎます',
EmailAuthException.userDisabled => 'このユーザーは無効です',
EmailAuthException.userNotFound => 'ユーザーが見つかりませんでした',
EmailAuthException.wrongPassword => 'パスワードが間違っています',
};
}

linkWithCredential
既にlinkされている情報を指定すると以下のエラーが返る(パスワード認証の場合)
case 'email-already-in-use':
print('The email address is already in use by another account.');