Skip to content Skip to sidebar Skip to footer

How Create New User With Firebase Api W/o Signing Out?

user signs in. I make a call to create new user with firebase.auth().createUserWithEmailAndPassword(email, password) it successfully creates new firebase user. Before this call f

Solution 1:

To add a new Firebase user without automatically switching to that user you can use a secondary Firebase instance to create the user. For example:

var firebaseConfig = {
  apiKey: "asdasdlkasjdlkadsj",
  authDomain: "asdfg-12345.firebaseapp.com",
  databaseURL: "https://asdfg-12345.firebaseio.com",
  storageBucket: "asdfg-12345.appspot.com",
};

firebase.initializeApp(firebaseConfig);  // Intialise "firebase"
var fbAdmin = firebase.initializeApp(firebaseConfig, "Secondary"); // Intialise "fbAdmin" as instance named "Secondary".

To create the user:

fbAdmin.auth().createUserWithEmailAndPassword(email, password)
 .then(function(newUser) {
  // Success. // Log out.
  fbAdmin.auth().signOut()
   .then(function () {
    // Sign-out successful.console.log('fbAdmin signed out.');
  }, function (error) {
    // An error happened.console.log('Error siging out of fbAdmin.');
    console.log(error);
  });
}, function (error) {
  // There's a problem here.console.log(error.code);
  console.log(error.message);
})

The above is for plain JavaScript. It's a bit trickier if you're using auto configuration to manage multiple environments. (See also Reserved URLs).

If you're using node.js you can use the Firebase Admin Node.js SDK. For requirements and set up information see the installation instructions.

Edit: Pretty much identical to this answer.

Post a Comment for "How Create New User With Firebase Api W/o Signing Out?"