I was working on a project which has an admin side, an admin could add another admins, and when an admin A add an admin B it automatically signin the admin B, so after many researches I found that firebase doesn’t provide any way to prevent or disable this behavior.
3
Answers
So I wanted to find the best solutions for a perfect user interaction, as we say features comes to fix bugs, So here is my alternative solution to hide this 'bug' :
Now let's write it in code (I'm using Rreact and @mui/material in my frontend) :
Frontend :
State :
Functions :
Images
It’s not recommended to create admin accounts on the front end as anyone could look into the code and action it themselves. You would want to create sufficient rules in the Firebase console to prevent users from editing other accounts etc. In fact, creating any new accounts but your own in the front end. This should all be controlled by Firebase’s Authentication service.
If you want to create an admin account, create a cloud function to do that and then just call the cloud function. Something like this:
My cloud function – I use custom user claims to make someone an admin as opposed to saving a ‘isAdmin’ property in the user’s document in firestore:
Then you can call this function from your app:
Note that my example takes an existing user and makes them an admin, you can just replace the get user with create user and then set the customerUserClaim and even trigger an email at this point to them if you want to be fancy. Let me know if this helped.
I think I’ve got the perfect solution (for vanilla JavaScript),
while creating the user itself you can use the signOut(auth) for preventing default signing in to the newly created user