Open4

Firebase Authのエラーコード

yorifujiyorifuji
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 => 'パスワードが間違っています',
      };
}