Firebase Auth, get a User UID before the user registers - firebase

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.

Related

Flutter account security using multiple auth verification

i want to make an application that check if the user is a real user. i want to create an double/multiple auth like some app did.
something like e-commerce app, the user create an account using login signup with firebase on flutter. when the user already sign in how can i check/ask user to did more verification something like 1 user account will need phone number and email verification to be able did something like upload a product or buying a product
i already make the user can be login using email, google sign in, an anonymus login
and once again how can i check if user is anonymus?
You can make use of the isAnonymous property of the user to know if the user is an anonymous user or a real authenticated user.
From your question it seems you want to re-authenticate the user before buying or uploading a product. For that you can use any of the following methods.
reauthenticateWithCredential
reauthenticateWithPhoneNumber
reauthenticateWithRedirect
reauthenticateWithPopup

Firebase, prevent user sign up by email password and google

I'm using Flutter and Firebase.
I allow new users to sign up using Email and Password, and also Apple and Google sign in.
Now I need to prevent the same user from creating an account with Email and Password, and a different account with Apple/Google sign in. As it is currently, they can create two accounts, and I see two different accounts in the Firebase console. Is there a way to make sure that once a user signed up with one method, he cannot sign up with another method? For example, check if that email already has a user associated with it?
Thanks

Limit each firebase user to only one auth provider?

How do I make it so that when a new user signs up in firebase, they can only login with that provider? Ex: a new user uses an email and password to sign up and then is rejected when trying to log in with Google.
I'm using Firebase with javascript in React if it helps.
What you're asking doesn't sound possible. The different auth providers don't know about each others' user bases. jackoboy on Google isn't at all related to jackoboy on Facebook. While they might have the same email address, that's never a guarantee that they are the same individual. So when jackoboy signs up with Google, there is nothing that can possibly stop jackoboy from also signing up with Facebook as a different account.
If you want to impose your own checks to see if the end user might be the same, you're going to have to write some code for that on a backend you control, then delete the second account if it appears to be the same person, by whatever logic you determine. Firebase Auth just isn't going to do that for you.

Firebase anon user to be linked to an email

Would anyone know how we could implement the following with Firebase auth. Docs/searches haven't produced a good answer yet. So the use case is as follows:
User comes to a site to buy something. We allow them to buy without any sign-up barrier and on checkout, just ask them for their email. An anonymous user is created and their purchase is sent to their email provided.
With that email, we'd like to set up a passwordless account for them so that the user can log in later just with their email and see items bought in their dashboard. For that the anon uid recorded with the purchase needs to be associated with the email.
So the question is how to achieve that an anon account upgraded to a registered account with the email provided.
We've tried inserting a passwordless sign-in link sending at the point of the purchase, but it just created a new account with a new id, which is not what's needed. We need the uid to stay the same as the anon user's so that we can simply connect their purchases to the newly email-authenticated account. Perhaps, there is a way of associating an anon uid with an email before sending that passwordless signin link?
Hope this makes sense, but please do ask if anything is unclear.
To create a Credential object from an email link, you can use the EmailAuthProvider.credentialWithLink method. You can then use this credentials object to upgrade your anonymous account.
Also see: Deleting User account with using Passwordless Authentication?

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.

Resources