I'm working on an enterprise application in which administrators create new users (there is no sign-up form). I am using Firebase Auth, which is great in many ways, but I've come across a problem for my use case. When you use firebase.auth().createUserWithEmailAndPassword(email, password), the user thereby created is automatically signed in. This obviously won't work when an admin is creating the user accounts. Is there any way to avoid this behavior? Thanks.
Asked
Active
Viewed 9,099 times
9
ed94133
- 1,477
- 2
- 19
- 40
-
2This is a good use case for the [Firebase Admin SDKs](https://firebase.google.com/docs/auth/admin/). Instead of creating the user client-side, you create the user in a managed environment, like a server or [Cloud Functions](https://firebase.google.com/docs/functions/). You have the client make a call to your endpoint when you want to add a new user. This [codelab](https://codelabs.developers.google.com/codelabs/firebase-admin/#0) shows how to incorporate custom claims using the Firebase Admin Auth SDK. This is a little different from what you're doing, but it can get you started. – Jen Person Sep 20 '18 at 22:11
-
Sounds like an answer Jen! :) If you can't use the Admin SDK, this is the only option: https://stackoverflow.com/questions/37517208/firebase-kicks-out-current-user – Frank van Puffelen Sep 20 '18 at 22:13
-
@JenPerson Great idea. I'll use the Admin SDKs. Feel free to make your comment the answer and I'll accept it. – ed94133 Sep 20 '18 at 22:48
-
Great! Let me know how the experience goes because we're always looking for new ways to improve documentation. – Jen Person Sep 21 '18 at 17:23
-
Already done and it worked great. If I didn’t just miss this option in the clientside docs, it might be a helpful cross-reference to include there for folks with this use case. – ed94133 Sep 21 '18 at 17:25
-
Another way is to store user information in the database like real time database. – Don Dilanga Dec 26 '20 at 11:10
1 Answers
11
This is a good use case for the Firebase Admin SDKs. Instead of creating the user client-side, you create the user in a managed environment, like a server or Cloud Functions. You have the client make a call to your endpoint when you want to add a new user. This codelab shows how to incorporate custom claims using the Firebase Admin Auth SDK. This is a little different from what you're exactly looking for, but it can get you started in the right direction.
Jen Person
- 7,356
- 22
- 30
-
2The mentioned codelab unfortunately does not exist anymore (404 - page not found). – Ulysses Alves Apr 20 '22 at 00:07