Home >Web Front-end >JS Tutorial >How Can I Prevent Firebase from Signing Out the Current User When Creating New Accounts?
When creating new user accounts using Firebase's createUserWithEmailAndPassword method, the currently logged-in user is automatically signed out. This behavior poses a challenge for administrators attempting to add multiple accounts while remaining signed in.
To overcome this issue, it is necessary to utilize a secondary Firebase app instance. Creating a user can be accomplished without signing out the current user by employing the newly created auth instance.
// Create a secondary Firebase app instance const secondaryApp = firebase.initializeApp(config, "Secondary"); // Use the secondary auth reference to create a new user secondaryApp.auth().createUserWithEmailAndPassword(email, password).then(function(user) { // Handle successful user creation });
It is crucial to consider the implications of using multiple auth references. While user creation is possible without authentication, writing data to Firebase may require the use of the appropriate auth reference with the necessary permissions. In the case of admin operations, the main auth reference should be utilized, while user-specific data should be written using the second auth reference.
The above is the detailed content of How Can I Prevent Firebase from Signing Out the Current User When Creating New Accounts?. For more information, please follow other related articles on the PHP Chinese website!