We are looking for a solution to a problem: how to handle authentication & user creation for multiple company clients, each client with their own users, within one Firebase. This is a desktop/mobile app.
Some details:
Each 'client' is actually a unique company, unrelated to other clients (companies), and do not share data nor users.
Authentication cannot rely on other products; Facebook, gmail etc is not an option, so email & password authentication is the login.
Assume our app is called HappyApp. Here's the generic structure
HappyApp
Client_1_Node
Users
some_uid's
Data
some_data
Client_2_Node
Users
some_uid's
Data
some_data
Pretty straight forward.
Here's the flow.
A potential user says 'Hey, I want to use HappyApp in our company because we want to be a happy company'.
The initial user (usually the company owner or head IT person) download's the app and is presented with an interface that allows him to enter their company name, other info, their email and a desired password.
The user is created in Firebase, their company data stored in a Client Node and can then login and use HappyApp. Because they are auth'd, they can now create app users so the other employees in their company can also login and use HappyApp and access their company data.
Here's the question: how does that initial user for this company get created?
The issue: a user cannot be created (in code) in firebase without the current user (the one that doing the creating) being auth'd.
Option 1: Hard code a master user into the app (the non-secure option)
The app has a 'master' user (user name & password) stored in code that can be used to authenticate to Firebase, and then create the client data; the new user along with the Client_1_Node and associated data. It's a simple solution but hard-coding user names or passwords in code is a bad idea.
Option 2: Roll an authentication server
A separate authentication server app (we'll call it auth_app) is rolled (along with hardware) that observes a 'new_user_request' node in Firebase that doesn't have security on it.
The auth_app has a 'master' user already auth'd and logged in (and always online) so it can create users and nodes in firebase as new clients (companies) download and start to use the app.
The sole job of the auth_app is to listen for new user requests (for new companies) and create that initial user and their client node in Firebase. The server could also be leveraged to email a user a temporary login password for the users initial login.
With this option, the user app writes a user request to firebase, the auth_app observes that request and then can create the new user in firebase, write out the Client_1_node data and then respond to the user app (via a firebase node the user app is observing) to tell it auth and log in
This option works but requires a server app and server hardware.
How can the initial user be created in firebase without either having a 'master' user hard-coded into the app or having a separate server to handle creating the initial user?
We don't think this is beyond the capability of Firebase but just not sure how to handle it.
Suggestions on how to create that initial user for each client (company)?
What's a better way to handle multiple clients (companies) within one firebase?