Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  166] [ 5]  / answers: 1 / hits: 41297  / 8 Years ago, mon, may 30, 2016, 12:00:00

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.



      //ADD EMPLOYEES
addEmployees: function(formData){
firebase.auth().createUserWithEmailAndPassword(formData.email, formData.password).then(function(data){
console.log(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?


More From » firebase

 Answers
18

Update 20161110 - original answer below



Also, check out this answer for a different approach.



Original answer



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: projectId.firebaseapp.com,
databaseURL: https://databaseName.firebaseio.com};
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
secondaryApp.auth().signOut();
});


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



Source for multiple app references.



EDIT



For the actual creation of a new user, it doesn't matter that there is nobody or someone else than 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, the main auth is the admin and the second auth is the newly created user.


[#61972] Friday, May 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hugo

Total Points: 21
Total Questions: 120
Total Answers: 107

Location: Belarus
Member since Tue, Jul 20, 2021
3 Years ago
;