2

I am building a booking system and I am using firebase as the backend. The system has two parts:

  1. the customer end which is an app.
  2. the business end which is a website.

I am using the same firestore database for both and also using the same Firebase Authentication project.

So I need two sets of authentication sets one for the customer end and another for the business end.

I have added two apps in a firebase project for sharing the database. My issue is the users shouldn't be able to sign in at the business web app with their credentials and vise versa.

How can I create two sets of authentication details one for each app?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Pranav Lari
  • 120
  • 7

1 Answers1

3

Authenticating a user with Firebase does not determine whether the user has access to anything app-specific. Authentication is merely a method where the user proves who they are.

You then use this information about the user to determine what they can do in your app(s), a process that is known as authorization. Authentication and authorization go hand in hand, but are still separate steps. And Firebase Authentication only takes care of the authentication part. Authorization is up to your app.

The typical approach to your scenario is to actually have only one set of credentials for each user. If the same user needs access to both the app, and the web site, they can sign in with the same credentials. Based on your knowledge of the user, you then grant or deny them access.

Most apps have a users collection with a user profile document for each user (using their UID as the key). Then after the user is authenticated your app could read the user's profile document and read for example two fields named isCustomer and isBusiness, to determine if the user has access to the app/site. You'd also use those fields in the security rules of your database to grant/deny access.

An alternative is to give each user profile in Firebase Authentication a custom claim to determine whether they are a customer and/or a business. In that case you'd need server-side code to set the custom isCustomer and/or isBusiness claims and use this in your code (and database) to grant or deny access.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807