21
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FirebaseAuthでのエラーハンドリング

Posted at

FirebaseAuthのエラーハンドリングについてあまり記事がまとまってなかったのでメモ :nerd:

各APIでどんなエラーが返ってくるのかはここを見ればわかります :point_down:
Firebase iOS Auth エラーの処理  |  Firebase

下記の通りにやろうとしたらいろいろ名前が変わっててエラったので対応。
ios - Reading Firebase Auth Error Thrown (Firebase 3.x and Swift) - Stack Overflow

具体的には、

  • FIRAuthErrorCode -> AuthErrorCodeのリネーム
  • switch文でのcase表記の変更

などをしています :bulb:

環境

swift 4
Firebase/Auth (5.14.0)

コード

Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
    if error == nil {
        // do something
    } else {
        if let errCode = AuthErrorCode(rawValue: error!._code) {
            switch errCode {
            case .invalidEmail:
                // メールアドレスの形式が違います。
            case .emailAlreadyInUse:
                // このメールアドレスはすでに使われています。
            case .weakPassword:
                // パスワードは6文字以上で入力してください。
            default:
                // エラーが起きました。\nしばらくしてから再度お試しください。
            }
        }
    }
}

以上です :hugging:

参考

21
13
2

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
21
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?