Viet Le Viet Le - 11 months ago 75
Javascript Question

Firebase kicks out current user

So I have this issue where every time I add a new user account, it kicks out the current user that is already signed in. I read the firebase api and it said that "If the new account was created, the user is signed in automatically" But they never said anything else about avoiding that.

addEmployees: function(formData){
firebase.auth().createUserWithEmailAndPassword(, formData.password).then(function(data){

I'm the admin and I'm adding accounts into my site. I would like it if I can add an account without being signed out and signed into the new account. Any way i can avoid this?

Answer Source

This is actually possible.

But not directly, the way to do it is to create a second auth reference and use that to create users:

var config = {apiKey: "apiKey",
    authDomain: "",
    databaseURL: ""};
var secondaryApp = firebase.initializeApp(config, "Secondary");

secondaryApp.auth().createUserWithEmailAndPassword(em, pwd).then(function(firebaseUser) {
    console.log("User " + firebaseUser.uid + " created successfully!");
    //I don't know if the next statement is necessary 

If you don't specify wich firebase connection you use for an operation it will use the first one by default.

Source for multiple app references.


For the actual creation of a new user it doesn't matter that there is nobody, or someone else then the admin, authenticated on the second auth reference because for creating an account all you need is the auth reference itself.

The following hasn't been tested but it is something to think about

The thing you do have to think about is writing data to firebase. Common practice is that users can edit/update their own user info so when you use the second auth reference for writing this should work. But if you have something like roles or permissions for that user make sure you write that with the auth reference that has the right permissions. In this case main auth is the admin and second auth is the newly created user.