4

I'm using the standard Email + Password auth-provider.

Through certain circumstances I have to create a firebase user manually. The flow would be something like calling a REST api with an defined email + generated password, and if succeeded sending a welcome email to the user with his password. Something like forward user registration.

I read through their docs and couldn't find much. (the new docs don't even offer a REST API section for user management.. well and just to be clear, the new "google" styled docs, pretty much suck anyway :) ).

Is there someone who has already done something similar and can help me out?

BTW: It would also be possible to create them client side through createUserWithEmailAndPassword(), but this function does automatically reauthenticate the new user, which must not happen in my scenario. Is it possible to use createUserWithEmailAndPassword() without automatically logging in the user?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Lukas
  • 1,346
  • 7
  • 24
  • 49

1 Answers1

7

You can create a new Firebase App context in your client and then call createUserWithEmailAndPassword() there:

var authApp = firebase.initializeApp({
  // ...
}, 'authApp');
var detachedAuth = authApp.auth();

detachedAuth.createUserWithEmailAndPassword('foo@example.com', 'asuperrandompassword');

By adding a second argument to initializeApp you create a separate context that will not trigger re-authentication upon user creation.

Lukas
  • 1,346
  • 7
  • 24
  • 49
Michael Bleigh
  • 25,334
  • 2
  • 79
  • 85
  • This is a great solution. I didn't think of this – Simon Oct 28 '16 at 14:34
  • @michael-bleigh is there any way for creating users with only phone numbers? I am building a solution for people who don't have emails and only have phone numbers. I am finding it hard to create accounts for them. – rbansal Nov 26 '21 at 17:16