问题
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?
回答1:
The answer give above by @bojeil is inaccurate and does not answer the question above. The correct answer would be:
Take a user through the standard IOS-Firebase phone verification process, then after a user is done you will hold a credential variable.
Use this variable to update a users phone number.
(NB: I am not an IOS developer, Google the correct method which to pass the credential variable. In Android that would have been user.updatePhoneNumber(phoneCredential)
)
回答2:
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)
Then do not use the following code
// Sign In The User
Auth.auth().signInAndRetrieveData(with: credential) { _, error in
}
But use this code
Auth.auth().currentUser?.linkAndRetrieveData(with: credential, completion: { _, error in
if error == nil {
print("Whopdee doo")
} else {
print("Aargh!!!")
}
})
来源:https://stackoverflow.com/questions/47633804/phoneauth-firebase-update-phone-number