如何在Swift 4中的Firebase身份验证中更新电子邮件地址 [英] How to update Email Address in Firebase Authentication in Swift 4

查看:34
本文介绍了如何在Swift 4中的Firebase身份验证中更新电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想更新当前用户的身份验证电子邮件地址.我已经尝试了很多解决方案,例如firebase的updateEmail方法,但是它不起作用!如果有人知道,那么请告诉我我该如何实现这一感谢!

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{
            }
        })
    }

推荐答案

要更改用户最近必须登录的电子邮件地址,我建议您这样做:

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
                }
            }
        }
    }
}

这篇关于如何在Swift 4中的Firebase身份验证中更新电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆