I am developing Android app using Firebase. Because of that, I want to use Firebase Auth. I have following requirements:
The first two are OK, I followed basic tutorials. However, Phone Number / Password is the problem here. Firebase supports only Phone Number/SMS Token for this (its called Phone Auth), but there is no mention about my case. I do not want to hack Firebase and use its realtime database instead of Auth 'database'. Is there any better way to achieve this?
Thank you.
Enable Phone Number sign-in for your Firebase project To sign in users by SMS, you must first enable the Phone Number sign-in method for your Firebase project: In the Firebase console, open the Authentication section. On the Sign-in Method page, enable the Phone Number sign-in method.
If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.
What is phone number authentication? Phone number authentication is an authentication method in which a sender sends an SMS message to a receiver's phone. Then, the receiver logs into its phone with a one-time code provided in the SMS message.
After adding his phone number, the user will click on the Get OTP button after that Firebase will send OTP on that number which is mentioned above.
Use Fake Email:
Well, Firebase doesn't support sign in with mobile number and password but it supports email and password. So you can create a fake email with your mobile number.
Ie: 78******[email protected]
Also, you can create a complete Authentication system using it.
Registration:
Input user mobile and password and proceed to the next page.
Now use Firebase Phone Auth (OTP) to createUser. If process success, link fake email, password credentials in background.
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
auth.getCurrentUser().linkWithCredential(credential);
Login:
signInWithEmailAndPassword()
.Forget Password:
If you have both email and phone of your user and you can use Admin SDK, then perhaps you could exchange users phone number to his email and login with email and password in the background.
Something like this (node.js)
admin.auth().getUserByPhoneNumber(phoneNumber)
.then(user => {
firebase.auth().signInWithEmailAndPassword(user.email, password);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With