[英]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.