Issue:
In Firebase, adding a new user account automatically signs in the new user and signs out the currently logged-in user.
Firebase API Statement:
"If the new account was created, the user is signed in automatically."
Goal:
Prevent the current user from being signed out when adding a new account (useful for admins managing user accounts).
Solution:
Use a Secondary Auth Reference
Create a new Firebase app instance using a different configuration:
var secondaryApp = firebase.initializeApp(config, "Secondary");
Use this secondary app instance to create new users:
secondaryApp.auth().createUserWithEmailAndPassword(em, pwd).then(function(firebaseUser) { // User created successfully });
Explanation:
By creating a separate auth reference, you can perform user management operations without affecting the currently logged-in user. The main auth reference is used by default for all operations, but by explicitly specifying the secondary reference, you can bypass the automatic sign-in behavior.
Additional Considerations:
The above is the detailed content of How Can I Prevent Firebase from Signing Out the Current User When Creating a New Account?. For more information, please follow other related articles on the PHP Chinese website!