Reputation: 596
I'm in the middle of developing an Android app using Firebase, and have Phone Number Authentication enabled as a method of user sign-in. This all works fine.
Inside my app, I have an Account Details page that allows the user to edit their information and update their record in the FirebaseDatabase (in a separate node that I have created and called users
). I'm able to update this table with no problems, but I need to update the table that Firebase keeps when users register, so that phone numbers don't get out of sync.
In theory, it should be really easy to do. I've done some reading up and seen that a method exists in the FirebaseUser
class called updatePhoneNumber(PhoneAuthCredential)
. The only problem is that I have no idea how the PhoneAuthCredential
class works and, after a couple of hours of Googling, haven't been able to find a single example, or many other forms of support for the method.
An example for the FirebaseUser.updateEmail(String)
method can be seen here, so I'd guess that it can't be all that different, and should work fine if I can get the PhoneAuthCredential
object set up correctly.
Update:
I tried to create an instance using new PhoneAuthCredential(...)
, but the suggested parameters aren't much help...
Android Studio displays the constructor as public PhoneAuthCredential(String s, String s1, boolean b, String s2, boolean b2, String s3)
, so I am very much none-the-wiser.
If I can figure out how to use this constructor, I might well be off the ground, hopefully.
If anyone can advise on how to use PhoneAuthCredential
, or how the FirebaseUser.updatePhoneNumber()
method should be implemented, that would be a huge help!
Thanks in advance,
Mark
Upvotes: 2
Views: 2871
Reputation: 4007
Phone auth is quite complicated, so I'd recommend reading this guide. This section is especially relevant to your case. Basically, you'll have to go through the entire phone auth flow again to get a credential and set the user's new phone number.
If you're thinking of the phone number as a part of the user's profile, that's incorrect as you can see from the profile request. The phone number is considered to be a sort of user identifier, like the email which also requires a credential if the user's sign-in action is 5 mins old. Hope this helps!
Upvotes: 1