AweSIM
AweSIM

Reputation: 1703

Firebase :: Create first user with roles

My app can users with roles OWNER, ADMIN or USER, in decreasing privileges. An OWNER can create ADMINs and USERs. An ADMIN can create USERs. A USER cannot create anything. There can be multiple OWNERs, ADMINs and USERs. Once the users have been created with relevant claims, this all works fine.

However, I do not understand how to create OWNERs in the first place. Do I create a cloud function that, when called, would create a new OWNER? What if someone can call it directly and create new OWNERs? How do I accomplish this?

Upvotes: 1

Views: 230

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50840

I just run a NodeJS script locally to add that one time role to a single user. You don't necessarily need Cloud Function but using it will save some time in setting up service account. Just use the Functions emulator locally by writing a one time function.

I have a detailed answer on that here: Firebase Custom Claims without Cloud functions

Once you add the OWNER claim, then you can deploy the same function to add claims to other users but just add a simple if statement to check if the caller has OWNER role or any role that can add the relevant roles.

Upvotes: 1

Related Questions