call method createUserWithEmailAndPassword without doing signIn
Clash Royale CLAN TAG#URR8PPP
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.
createUserWithEmailAndPassword
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?
createUserWithEmailAndPassword
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);
3 Answers
3
[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('foo@example.com', '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!
I hope you can tell me the workflow, so is the flow like this: 1. Sign-up with email and password 2. Close browser 3. Open again, still signed-in or 1. New user but already have record in the auth (you change in the auth section yourself beforehand) 2. They can sign in without sign up themself. OR? Give us scenario to help you
– Angus Tay
Aug 8 at 2:01
1. Through an authenticated user I create another user. 2. When creating a user, you must continue logged in with the user who created the new user instead of changing for the created user. SOLUTION: When I call the
createUserWithEmailAndPassword ()
method it automatically sets the user created as the authenticated user and I do not want this to happen.– Luiz
Aug 8 at 2:07
createUserWithEmailAndPassword ()
@Luiz Oh, you mean when user A somehow use your website to create a new account for user B, after signing-up, user A is logged out but user B is signed-in?
– Angus Tay
Aug 8 at 2:09
That's right ... user A is an administrator user and this is creating a new user B for someone else to access, but user A must remain authenticated after user B has been created.
– Luiz
Aug 8 at 2:15
Sounds like an administrator function. See Introduction to the Admin Auth API
It is not always convenient to have to visit the Firebase console in
order to manage your Firebase users. The admin user management API
provides programmatic access to those same users. It even allows you
to do things the Firebase console cannot, such as retrieving a user's
full data and changing a user's password, email address or phone
number.
Sorry but this has nothing to do with my question ...
– Luiz
Aug 8 at 1:51
my bad, I read
Is there a way to create users from an authenticated user
to mean an admin type role. Can you elaborate on what type of user you want to allow access to create other users (via the email method)?– Ron Royston
Aug 8 at 1:56
Is there a way to create users from an authenticated user
It is an administrator user who is allowed to create other users ... But when I create a user being that I am with that authenticated user (administrator) it changes the authentication state for the created user.
– Luiz
Aug 8 at 2:03
Any reason you can't stand up a node server and user the Admin SDK to handle these moves, adds, and changes (MAC's)? It's a easy, quick, and free... (e.g. cloud9 IDE private workspace or on your laptop)?
– Ron Royston
Aug 8 at 2:06
After create user, you need call the signInWithEmailAndPassword
sign in.
signInWithEmailAndPassword
signInFirebaseWithEmailAndPassword(
userName: string,
password: string
): Promise<firebase.auth.UserCredential>
return this._angularFireAuth.auth.signInWithEmailAndPassword(userName, password);
I do not want to change the status of the authenticated user, so do not avoid changing the status of the authenticated user ...
– Luiz
Aug 8 at 2:50
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I want to keep the user authenticated when a new user is created, in my system it is possible to create users when there is an authenticated user.
– Luiz
Aug 8 at 1:54