0

I am designing my web application using firebase in which the admin had to create the user accounts. I am using createUserWithEmailandPassword method to create the user acccounts.

firebase.auth().createUserWithEmailAndPassword(email, password)
.catch(function(error) {
});

But whenever i use this method to create an account the admin accounts gets signed out and is signed in with the newly created user account.

I don't want to be signed in with newly created account and should be continued with the old admin account. Please tell me an alternative for this.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
this is yash
  • 533
  • 1
  • 3
  • 15
  • 1
    https://firebase.google.com/docs/auth/admin/manage-users You should use the Admin SDk – niclas_4 Dec 11 '18 at 10:35
  • Hi @Badgy i am not using node js in my project, just using javascript by importing from firebase cdn links .... infact if we use Node Js, there is a feature called as admiin, by which my requirment can be achieved. Thanks for the answer – this is yash Dec 11 '18 at 12:06
  • This is the expected behavior: the Firebase JavaScript SDK is meant to be used for signing in regular users, not for admin activities. If you can't use the Admin SDK that Badgy commented about, have a look at the answers to this question: https://stackoverflow.com/questions/37517208/firebase-kicks-out-current-user, which are in line with what Badgy and Jack commented/answered. – Frank van Puffelen Dec 11 '18 at 14:44

1 Answers1

0

I initialise two apps for this need and make sure when creating accounts i use the second app. This way i can create the users and although the user gets logged into the new account its on the second firebase app so is isolated from the websites logic. More info on setting up multiple apps here

// Initialize the app
firebase.initializeApp(appConfig);

// Initialize another app with a same config
var createUserApp = firebase.initializeApp(appConfig, "createUserApp");

// You can then access the other app to create the user like this
createUserApp.firebase.auth().createUserWithEmailAndPassword(email, password)

Your other option is to use the admin sdk.

Jack Woodward
  • 991
  • 5
  • 9
  • Hi Jack Woodard, i am not using node js in my project, just using javascript by importing from firebase cdn links .... infact if we use Node Js, there is a feature called as admiin, by which my requirment can be achieved. Thanks for the answer – this is yash Dec 11 '18 at 12:06
  • No worries, both approaches will work, depends on the level of work you want to do as the example showed is very low effort from dev effort but implementing nodejs version on a server is more work but more scalable with bulk actions to create many users etc – Jack Woodward Dec 11 '18 at 13:07