2016-07-16 3 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

here를 찾을 수 있습니다 그것은했다. 대답으로 표시했습니다. 감사. –

+1

@AmadeuAndrade Nice! 다행 했어! – 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) 
     } 
    }) 
} 

중포 기지 문서가