How to reauthenticate user who signed in with phone number in firebase? - firebase

Hi I need to add the option for users to delete their accounts from within the app but I just don´t know how to do it, I found some information here where it explains that we need to ask the user to sign in again otherwise we´ll get an error, but it only explains how to reauthenticate the user when this signed in using an email address and it does not say anything about when a phone number was used instead.

Related

How to link a backup email address to a firebase phone authentication?

I'm using a Firebase phone auth as primary authentication. Since the phone is vulnerable, I want to link an email address to it that the user can use to access his account to change his phone number in case he lost his phone or got stolen. I can't find a way how to do it.
I saw a method currentUser.linkWithPhoneNumber(). However, reading its documentation, it says it is only supported on web platforms. Is there any other way to make this possible?
When you authenticate a user with a phone number, the only data that you have inside the FirebaseUser object when the authentication completes, are the UID and the phone number. If you need to add an email address to an existing account, you can request the user to provide an email address. Once you have that, you can update the email address using the FirebaseUser#updateEmail(String email) function. As soon as the account is updated, you can add any functionality related to that email address.
Since you didn't specify a programming language, I linked that function to the Android docs, but certainly, you can do the same thing in the case of any other programming languages.
upon further reading, i found Email Link Authentication that answered everything i've asked.
Linking/re-authentication with email link You can also link this method of authentication to an existing user. For example a user previously authenticated with another provider, such as a phone number, can add this method of sign-in to their existing account.
https://firebase.google.com/docs/auth/flutter/email-link-auth

Firebase Auth, get a User UID before the user registers

I am developing an invitation mechanism to our app. New users will be invited with their e-mail addresses or their telephone numbers. I would like to keep some records about the invited but non-registered user. So, I want to have their Firebase Auth User UID before they even signed up. Is this possible? Maybe using Firebase Admin SDK?
I don't want to use their e-mail addresses or telephone numbers to refer to them because UID feels like a better identifier. However, UID is not there before they sign up, right?
We toyed with creating a user and generating a passwordless login for them, etc. But whatever we do seems to mess with the initial sign up of users. It would be great if we could just get a UID and let the user sign up later.
You cannot create a user account, and then have the user "sign up" with the same UID. So you will have to handle your "sign up" flow a little differently.
In this demo an administrator creates a user account, and then invites the user to sign in by sending them an authentication code (jump ahead to the 3:00 minute mark in the recording). Then the user is allowed to sign in and activate their account by presenting the authentication code.
You can try to build something similar. For example you can save a flag for each new user in the database, and then clear that flag in a custom sign up action.

Firebase authentication only converts Facebook and Email auth to Google auth, But Not vice versa

I knew it is raised already, but i want to clear and sum it up.
I use FireBase authentication to allow the following Sign Up:
Facebook
Google
Email
When signed up with Email, but later decide you want to change credential to Facebook (Having the same email) You receive an error. Same issue from Google to Facebook.
The Error:
An account already exists with the same email address but different
sign-in credentials. Sign in using a provider associated with this
email address.
However, if you Logged with Facebook or Email you CAN change your credential to Google.
Theoretically you can allow multiple accounts with the same email:
However, it means (from what i understood) Firebase auth will generate a unique UserID for each additional credential which means that if you use UserID to track data of user (messages, score, etc..) you need somehow track all UserIDs from all credentials. This can ruin one of Firebase authentication purposes.
If you decide to go this way, you will need to link the accounts using LinkWithCredentialAsync. As i understood this can be ONLY be done if you are LOGGED IN with your other credential.
I rising this because i was disappointed to discover this only after implementing Firebase.
The solution from this thread Stackoverflow thread is creative (see pupadupa scheme), but i do not want to go this way.
If someone can add on to this and found some sort of solution, please post it.

disable sign up with signInWithPhoneNumber in fireabase

I just use two methods on my web app.
SignInWithEmail
SignInWithPhoneNumber
And I want users can sign up with user&password which is possible now and then I get their phone number. So they can sing in with the phone number for the next time. But if someone put an unexcited phone number in sign in page it didn't show an error to say that phone number doesn't exist. And firebase just signed up that phone number!
I just want users could sign up for email and password!
SignInWithPhoneNumber method will automatically sign up a new user if user doesn't exist. You can check if the returned user is a new user and if it's new, delete and sign out the user manually.
Firebase Auth provides the tools needed for building this. As Ti pointed it out, Firebase Auth returns isNewUser in firebase.auth.UserCredential returned on sign in/sign up. You can inspect that to tell if a phone number user is existing or new and wire your logic from there. You also have the ability to ask the user to provide their email/password afterwards. You can use linkWithCredential to link an email/password credential.

How to allow user to sign in with both email and phone number?

I have firebase name and email authentication in my android app. I also have phone number auth in my app.
I want to link name and email with phone, so that user can sign in with phone number and password, if he forgets email or gets bore to type long email.
Depending on whether you want to allow for signing in with either email or phone number, or if you want to allow for the Phone number to be used as a second factor, for sign in, there are different solutions.
If you just want to have the Phone number be a second way to sign in, you can link the credentials using the linkWithCredential method on your Firebase User. This way you can add as many ways to sign in, as you want. Firebase has a good guide on this.
If you want the phone number to be a second factor of authentication, you will need to have a custom auth provider, which does the second factor authentication. There is also a getting started guide on this, however the 2 Factor Authentication part itself would be up to you.

Resources