How to update Only Email Address in Firebase Authentication For iOS Swift 4

ぃ、小莉子 提交于 2020-01-06 08:01:15

问题


i just want to update authenticate email address of current user. i have tried lot's of solution like updateEmail method of firebase but it not work !! if any one know then please tell me how can i achieved this Thanks in advance !!

@IBAction func btnResetEmailClick(_ sender: UIButton) {
        let auth = Auth.auth()
        guard let email = self.txtEmailAddress.text ?? auth.currentUser?.email else { return }
        // email that i have to update with current user email
        auth.currentUser?.updateEmail(to: (auth.currentUser?.email)!, completion: { (error) in
            if error == nil{

            }else{
            }
        })
    }

回答1:


To change the email address the user has to be logged in recently i would suggest doing this:

var credential: AuthCredential

@IBAction func changeEmail() {
    if let user = Auth.auth().currentUser {
        // re authenticate the user
        user.reauthenticate(with: credential) { error in
            if let error = error {
                // An error happened.
            } else {
                // User re-authenticated.
                user.updateEmail(to: "email") { (error) in
                    // email updated
                }
            }
        }
    }
}



回答2:


This is effective method to solve it.

let user = Auth.auth().currentUser
user?.updateEmail(to: "email") { error in
if error != nil {
    // An error happened
} else {
   // Email updated.
   }
}


来源:https://stackoverflow.com/questions/54958026/how-to-update-only-email-address-in-firebase-authentication-for-ios-swift-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!