Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase users setting phone number

I have been authenticating user from facebook on firebase but i want to make them set their phone numbers linked to the user but i cant find any way to make them set their phone number i can only retrieve using FirebaseUser user.getPhoneNumber and update phonenumber needs credentials not string which i don't know how to use so can anyone help me ?!

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.getPhoneNumber();

user.updatePhoneNumber();

like image 497
Hany Abd El Moniem Avatar asked Jul 25 '17 13:07

Hany Abd El Moniem


1 Answers

Firebase Auth verifies its own phone numbers. It doesn't populate Facebook phone numbers after a Facebook sign-in or something of the like. However, if you have the phone number, you need to go through the verification process: verifyPhoneNumber with the phone number to get the verificationId and then ask the user for the SMS code, populate a phone auth credential using the verification ID/code and then call user.updatePhoneNumber(phoneCredential).

Alternatively, if you already verified the phone number via some other means, you can send the user ID token and the phone number to your server. Using the Firebase Admin Node.js SDK, verify the ID token and then call updateUser API with the phone number: https://firebase.google.com/docs/auth/admin/manage-users#update_a_user You then user.reload() the user on the client to update with the phone number.

like image 128
bojeil Avatar answered Oct 24 '22 13:10

bojeil