2016-07-16 7 views

答えて

11

パスワードを変更する前にreauthenticateを使用して達成することができます。あなたが使用しているものは何でもプロバイダの資格情報オブジェクトを設定する方法を見つけることができます

let user = FIRAuth.auth()?.currentUser 
let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: currentPassword)  

user?.reauthenticateWithCredential(credential, completion: { (error) in 
    if error != nil{ 
     self.displayAlertMessage("Error reauthenticating user") 
    }else{ 
     //change to new password 
    } 
}) 

ただ、より多くの情報を追加するために、here。スウィフト4については

+1

を見つけることができます。私は答えとしてマークした。ありがとう。 –

+1

@AmadeuAndradeニース!うれしいuはそれを作った! – adolfosrs

0

typealias Completion = (Error?) -> Void 

func changePassword(email: String, currentPassword: String, newPassword: String, completion: @escaping Completion) { 
    let credential = EmailAuthProvider.credential(withEmail: email, password: currentPassword) 
    Auth.auth().currentUser?.reauthenticate(with: credential, completion: { (error) in 
     if error == nil { 
      currentUser.updatePassword(to: newPassword) { (errror) in 
       completion(errror) 
      } 
     } else { 
      completion(error) 
     } 
    }) 
} 

Firebaseドキュメントは、それが働いたhere

関連する問題