LoginSignup
4

More than 5 years have passed since last update.

Firebase Authenticationでreauthするときの対処法

Last updated at Posted at 2018-06-08

背景

Firebaseのメールの再設定の機能とかパスワード再設定の機能を作っていたらreauthrizationのところでAuthCredentialの作り方が公式になくて困っていました。
しばらく予測でそれっぽいクラスとか関数を探して回っていたらあったので一安心。

環境

Xcode: Version 9.4
Swift: Version 4系
Firebase Authentication: EmailとPasswordでやるやつです。

対処法

if let user = Auth.auth().currentUser {
    let email = user.email
    let password = **** //ここでパスワードを取得
    let credential = EmailAuthProvider.credential(withEmail: email!, password: "")
    user.reauthenticate(with: credential, completion: { (error) in
        if let error = error { //失敗
            self.showAlert(error.localizedDescription)
        } else {
            //success
        }
    })
}

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
4