LoginSignup
13
5

More than 3 years have passed since last update.

firebase authentication(JavaScript SDK)サインイン時のエラーハンドリング

Posted at

Firebase Authentication(JavaScript SDK)でメールアドレス、パスワードを利用してサインインする場合に、throwされるエラーをまとめました。

ドキュメントに記述されてますが、以下のエラーがthrowされるので、エラーに応じて適切に処理することになります。

  • メールアドレスの形式がおかしい
    • errorCode: auth/invalid-email
    • message: The email address is badly formatted.
  • ユーザが無効になっている
    • errorCode: auth/user-disabled
    • message: The user account has been disabled by an administrator.
  • ユーザが存在しない
    • errorCode: auth/user-not-found
    • message: There is no user record corresponding to this identifier. The user may have been deleted.
  • パスワードが間違っている
    • errorCode: auth/wrong-password
    • message: The password is invalid or the user does not have a password.

また、パスワードを5回間違えると、以下のエラーが返ってきます。

try {
  const data = await firebaseAuth.signInWithEmailAndPassword(
    "email-adress@example.com",
    "password"
  )
} catch (error) {
  if (error.code === 'auth/invalid-email') {
    // メールアドレスの形式がおかしい
  } else if(error.code === 'auth/user-disabled') {
    // ユーザが無効になっている
  } else if(error.code === 'auth/user-not-found') {
    // ユーザが存在しない
  } else if(error.code === 'auth/wrong-password') {
    // パスワードが間違っている
  } else if (error.code === 'auth/too-many-requests') {
    // 何度もパスワードを間違えた
  } else {
    // その他
  }
}
13
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
5