PhoneAuth Firebase:更新电话号码 [英] PhoneAuth Firebase: Update Phone number

查看:58
本文介绍了PhoneAuth Firebase:更新电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了Firebase电话身份验证,以验证项目中的电话号码及其对我的正常运行,但是无法更新电话号码.就像用户登录了电话号码A,现在他想将其更新为电话号码B一样.

I have implemented firebase phone auth to verify phone number in my project and its working fine for me, But not able to update phone number. Like if a user had logged in with phone number A and now he wants to update this to phone number B. How will it be solved?

推荐答案

我找到了一个答案,您在此使用电子邮件帐户登录并将手机号码更新为同一帐户.您可以使用该解决方案登录电话,然后将电话号码更新到同一帐户中,然后查看其是否有效.无论如何,我将在我的项目中研究这个确切的解决方案,然后更新答案.但是在那之前,您可以尝试看看是否可行.请按照此处提供的常规Firebase电话身份验证过程进行操作: https://firebase.google .com/docs/auth/ios/phone-auth

I have found an answer where you log in with your email account and update the mobile number into the same account. You may use the solution to log in with phone and update the phone number into the same account and see if it works. Anyway I will be working on this exact solution down in my project and update the answer then. But until then you can try to see if this works. Follow the regular firebase phone auth procedure as given here : https://firebase.google.com/docs/auth/ios/phone-auth

PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in
  if let error = error {
    self.showMessagePrompt(error.localizedDescription)
    return
  }
  // Sign in using the verificationID and the code sent to the user
  // ...
}

let credential = PhoneAuthProvider.provider().credential(
    withVerificationID: verificationID,
    verificationCode: verificationCode)

然后不要使用以下代码

// Sign In The User
Auth.auth().signInAndRetrieveData(with: credential) { _, error in

}

但是使用此代码

Auth.auth().currentUser?.linkAndRetrieveData(with: credential, completion: { _, error in

    if error == nil {
        print("Whopdee doo")

    } else {
        print("Aargh!!!")
    }
})

这篇关于PhoneAuth Firebase:更新电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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