0

I am creating a firebase project. It contains two React webapps: a client facing app and a backoffice app.
I either:

  • create two apps in Firebase with separate configurations, and two hosting sites
  • or keep a single app in Firebase and use its config in both React apps, and two hosting sites
    In my understanding, the apps can access the same resources either way.

What should I do?
More precisely: what is the benefit of separating Web apps in Firebase ?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Louis Coulet
  • 3,663
  • 1
  • 21
  • 39
  • The benefit is whatever personal convenience you get from separating the two, if that's what you want to do. What you're asking is a matter of opinion. – Doug Stevenson Sep 01 '20 at 16:07
  • Thanks for your comment, but I feel that I fail to convey my question. My web apps are separated well enough in my code, and have different hosting sites, but I would like to understand in what aspect would creating two firebase apps would increase the separation? – Louis Coulet Sep 01 '20 at 16:41
  • 1
    If you don't intend to configure the Firebase products within each app differently, then there is not much practical difference. You would need to visit specific use cases and ask if separate apps help or hurt that case. Those use cases are more likely to revolve around .analytics rather than development. – Doug Stevenson Sep 01 '20 at 16:46
  • Exactly the info that I was after! I cannot find anything about this feature, not helped by the fact that it has no specific name. Could you please share any relevant documentation if you happen to know some? – Louis Coulet Sep 01 '20 at 19:55
  • Also, if you set your last comment as an answer, I can accept it and close the question. – Louis Coulet Sep 01 '20 at 20:10

2 Answers2

2

What is the benefit of separating Web apps in Firebase?

In your case, i.e. "a client facing app and a back-office app", you probably have different user roles:

  • Clients who use the client facing app (maybe with different sub-roles, e.g. authors and editors or team leader and team members, depending on the business scope of your app)
  • Admins or Super-users, or "back-office clerks", etc... who use the back-office app.

The classical way to handle this role-based access control strategy with Firebase is to use Custom Claims.

In addition to implementing a way to grant (or not) access rights based on roles, Custom Claims also allow you to adapt your app UI depending on the user's role or access level.

This is interesting but if your app is complex and have several screens (or menus) that have different behaviors depending on the user role it can rapidly become a nightmare to hide/show parts of the UI depending on a variable. In this case it may be better to have two separate apps (in two separate Firebase projects) that point to the same (master) Firebase project.

Having two separate apps is also very interesting if different developers/development teams works on the two apps.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • Thank you for your detailed answer, it adds interesting info. Indeed I plan to build two separate React apps for client and admin, for they are too different for conditional rendering into a single app. Concerning Custom Claims, if I understand correctly, the user signs in, then requests his additional claims, then requests a token refresh, so 3 round-trips with incomplete state in the meantime, am I correct? – Louis Coulet Sep 01 '20 at 20:05
  • Custom Claims are accessible via user's authentication tokens. No additional processing or lookup is needed to check for Custom Claims and associated roles/permissions. For more details, see [here](https://firebase.google.com/docs/auth/admin/custom-claims), [here](https://stackoverflow.com/a/52732200/3371862) and [here](https://stackoverflow.com/a/54594212/3371862). – Renaud Tarnec Sep 01 '20 at 20:21
  • Since all user accounts are shared between all apps within a project, there really isn't a strong advantage using different apps within a single project, with respect to Firebase Auth and its custom claims. You can segregate users into permissioned groups with custom claims using just a single app instance just fine. Using a second app is merely organizational in this respect - and if that's your preference, then run with it! – Doug Stevenson Sep 01 '20 at 20:55
  • Thank you for your answers, tomorrow I will explore Custom Claims and see if it improves over keeping the claims simply as firestore fields. Firebase rocks! – Louis Coulet Sep 01 '20 at 21:04
2

If you don't intend to configure the Firebase products within each app differently, then there is not much practical difference. You would need to visit specific use cases, then ask if separate apps help or hurt that case. The use cases where separate apps would be more helpful are likely to revolve around Analytics rather than development. Analytics and its related products use the concept of an application to generate meaningful data about that app, and also create and target audiences within those specific apps.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441