简体   繁体   English

Firebase 更新电子邮件和电话号码。 “此操作很敏感,需要最近的身份验证。” updateEmail ios swift 上的错误

[英]Firebase Update Email and Phone number. “this operation is sensitive and requires recent authentication.” Error on updateEmail ios swift

I have a profile page in my app, where user can update phone number and email, so while updating email i am getting this error "this operation is sensitive and requires recent authentication"我的应用程序中有一个个人资料页面,用户可以在其中更新电话号码和电子邮件,因此在更新电子邮件时我收到此错误“此操作很敏感,需要最近的身份验证”

Here is my code for update email这是我的更新电子邮件代码

Auth.auth().currentUser?.updateEmail(to: self.txtEmail.text ?? "", completion: { (err) in
                            
                        })

So i decided to use updatePhoneNumber method so it will show otp prompt and so phone number update is done in that method and we can consider it at recent login, so in completion block of updatePhoennumber method i am using updateemail method but still getting same error is there any other solution?所以我决定使用 updatePhoneNumber 方法,所以它会显示 otp 提示,所以电话号码更新是在那个方法中完成的,我们可以在最近登录时考虑它,所以在 updatePhoennumber 方法的完成块中我使用的是 updateemail 方法,但仍然得到相同的错误还有其他解决方案吗? we are not creating account with password so i don't have password for that email.我们没有使用密码创建帐户,所以我没有该电子邮件的密码。 So please let me know if i can do both operation in single verification.所以请让我知道我是否可以在单次验证中完成这两个操作。 Below is my code下面是我的代码

    let credential = PhoneAuthProvider.provider().credential(
                withVerificationID: verificationId,
                verificationCode: verificationCode)
            if let user = Auth.auth().currentUser {
                
                user.updatePhoneNumber(credential) { (err) in
                    if let error = err {
                        
                        return
                    } else {

Auth.auth().currentUser?.updateEmail(to: self.txtEmail.text ?? "", completion: { (err) in
                                
                            })}

Please let me know if there is any other way to achieve it.请让我知道是否有任何其他方法可以实现它。

You must re-authenticate the user using reauthenticateWithCredential:completion: on the FIRUser object.您必须在FIRUser对象上使用reauthenticateWithCredential:completion:重新验证用户。 First, obtain the user's credentials (here are two examples):首先,获取用户的凭据(这里有两个示例):

let emailCredential = EmailAuthProvider.credential(withEmail: "some@email.com", password: "somePassword")
let facebookCredential = FacebookAuthProvider.credential(withAccessToken: "someToken")
// or other

And then pass it into the reauthenticate method:然后将其传递给 reauthenticate 方法:

Auth.auth().currentUser?.reauthenticate(with: emailCredential, completion: { (result, error) in
    // go from here
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM