Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can handle separate login for two types of users in same firebase app?

I have a scenario and looking solution for that. I am working on an application and Using Firebase to create and authenticate the User. In my app, basically two types of users (1.User & 2. Vender) and User can signIn on app but vender need to login on web panel. We are using firebase default method (.createUser) to create user and it's already working. Now I wants to create Vender profile too in same app but Vender can login only on web app and user can login on Mobile app.

Is it possible ? If yes then please guide me that how it's possible ?

Thanks in advance.

like image 726
Purushottam Avatar asked Apr 06 '16 13:04

Purushottam


People also ask

Can you create a user with the same credentials in Firebase?

Firebase account linking allows users to sign into the same account using different authentication providers. By linking the user's Facebook and Twitter credentials, for example, the user can sign into the same account using either sign-in provider.

How do I detect if a user is already logged in Firebase?

To detect if a user is already logged in Firebase with JavaScript, we can call the onAuthStateChanged method. firebase. auth(). onAuthStateChanged((user) => { if (user) { // ... } else { // ... } });


1 Answers

This is a fairly open-ended question but I think it comes down to two things: determining the user type (vendor or user) and detecting what platform they are signing up on.

Both are pretty easy.

Heres's the structure which leverages a /users node to store additional info about the user. From Storing User Data

users
  uid_0
   name: "William:
   type: "vendor"
  uid_1
   name: "Leonard"
   type: "user"

and then when the user attempts to log in, the app checks their user authentication, which will result with authData.uid being populated.

Then it would look up the user via authData.uid and check the user type. If it's a Vendor, display a message to the user that they must log in via the web portal, and don't proceed into the app.

There's a 100 other ways to handle this - setting up a Vendors Node and a Users node for the app to auth against to having them select Vendor Or User before entering their authentication credentials.

like image 133
Jay Avatar answered Oct 08 '22 20:10

Jay