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);
}
[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:
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.
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.
Other reference: How to keep user logged in with Firebase no matter what?
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With