Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call method createUserWithEmailAndPassword without doing signIn

In my system I need to create users from an authenticated user, but for this I need to create a user through the createUserWithEmailAndPassword method and when I create the user through this method the authentication status changes to the user that was created at the moment.

Is there a way to create users from an authenticated user without making signIn for the user created after it was created by the createUserWithEmailAndPassword method?

I have a system developed in Angular + Node.js

  createUser(user: Usuario): Promise<firebase.auth.UserCredential> {
    return this._angularFireAuth.auth.createUserWithEmailAndPassword(user.email, user.password);
  }
like image 580
Luiz Avatar asked Sep 02 '25 04:09

Luiz


1 Answers

[ANSWER]

You can create a new Firebase App context in your client and then call createUserWithEmailAndPassword() again. This will not be re-authenticate to the the new user created. Reference.

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

detachedAuth.createUserWithEmailAndPassword('[email protected]', 'asuperrandompassword');

Potential Problem when doing this is: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).

[OTHER SCENARIO (for others references)]

I assume you meant either one of these:

  1. You want the signed-in user to keep signed-in even after closing the browser. If this is the case, you could use the persistence provide by the firebase auth.

  2. You want to hide your sign-in button when the user state change from "not signed-in" to "signed-in". Then you can check this post.

  3. Other reference: How to keep user logged in with Firebase no matter what?

Hope it helps!

like image 168
Angus Tay Avatar answered Sep 05 '25 01:09

Angus Tay