ios - 如何在 Swift 4 中更新 Firebase 身份验证中的电子邮件地址

标签 ios firebase firebase-authentication swift4

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

enter image description here

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

最佳答案

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

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

关于ios - 如何在 Swift 4 中更新 Firebase 身份验证中的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54958026/

相关文章:

reactjs - 无法打开连接到firebase的heroku应用程序

python - 如何使用 Python 向 Firebase 进行身份验证?

ios - ios chrome 上大小不同的 unicode 圆圈

ios - 如何在应用程序终止或终止时点击推送通知后打开特定 Controller

ios - 使用 Xcode 8+ 和 Swift 3+ 与 MapKit 进行集群

ios - 如何获取rct-image-store ://0的绝对路径

swift - Firebase 和 Facebook 身份验证

angular - 从 Web 应用程序中从 firestore 删除字段时出错。 "Unsupported field value: a custom DeleteFieldValueImpl object"

javascript - 检索 Firebase 数据并返回它的最佳方式,或其他方式

javascript - Firebase 密码验证不起作用