简体   繁体   English

在 Firebase 身份验证中更新电话号码 - Swift

[英]Update Phone Number in Firebase Authentication - Swift

Is there a way to update the phone number in firebase auth?有没有办法更新firebase auth?的电话号码auth? The thing is if the user entered a wrong number in registration then can I update the old number to new one then send the verification code in that new number?问题是如果用户在注册时输入了错误的号码,那么我可以将旧号码更新为新号码,然后在该新号码中发送验证码吗? How can I achieve this?我怎样才能做到这一点?

There is a method on the User object called updatePhoneNumber , which seems to be what you want. User对象上有一个名为updatePhoneNumber ,这似乎是您想要的。

The documentation doesn't mention anything about what this does to the verification status, although I'd assume it indeed will require the new number to be verified too.该文档没有提及这对验证状态有何影响,尽管我认为它确实也需要验证新号码。 Give it a try, and let me know if that isn't the case.试一试,如果不是这样,请告诉我。

You're welcome别客气

Auth.auth().currentUser?.updatePhoneNumber(credential, completion: { (error) in
            if error == nil {
                print("succes")
            }
        })

On the screen where the user has to enter their phone number:在用户必须输入电话号码的屏幕上:

var verificationId: String?

PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumberTextField.text!, uiDelegate: nil) { (verificationID, error) in

    if let error = error { return }

    self.verificationId = verificationID else { return }
}

On the screen where the user has to enter the sms verification code:在用户必须输入短信验证码的屏幕上:

let credential = PhoneAuthProvider.provider().credential(withVerificationID: self.verificationId!, verificationCode: smsTextField.text!)

Auth.auth().currentUser?.updatePhoneNumber(credential, completion: { (error) in

    if let error = error { return }
})

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

相关问题 Firebase 认证:Swift 中的电话号码认证 - Firebase Authentication : Phone number authentication in Swift Firebase 更新电子邮件和电话号码。 “此操作很敏感,需要最近的身份验证。” updateEmail ios swift 上的错误 - Firebase Update Email and Phone number. “this operation is sensitive and requires recent authentication.” Error on updateEmail ios swift Firebase电话号码身份验证错误 - Firebase Phone number authentication Error PhoneAuth Firebase:更新电话号码 - PhoneAuth Firebase: Update Phone number 设备无法使用Firebase身份验证电话号码 - Device not working with Firebase Authentication Phone Number 是否可以在Firebase中使用电子邮件和电话号码进行身份验证? - Is it possible to use email and phone number to authentication in Firebase? 离子电容 Firebase 电话号码认证问题 - Ionic Capacitor Firebase Phone Number Authentication Problems 电话号码身份验证不适用于 IOS 设备 [Firebase] - Authentication of phone number is not working on IOS Devices [Firebase] 如何在 Swift 4 中更新 Firebase 身份验证中的电子邮件地址 - How to update Email Address in Firebase Authentication in Swift 4 如何使用Swift在Firebase中添加电话身份验证? - How can I add phone authentication in firebase using swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM