Home >Web Front-end >JS Tutorial >How Can I Create Firebase User Accounts Without Signing Out the Current User?
Firebase and Automatic User Sign-In
Issue
Creating a new user account with Firebase prompts the platform to sign out the currently signed-in user. This action presents a challenge for administrators seeking to add accounts without interrupting their own sessions.
Firebase Authentication Behavior
Firebase documentation states that creating a new account automatically triggers the signing in of that user. However, it does not offer any guidance on overriding this behavior.
Solution: Using a Secondary Authentication Reference
To avoid signing out the current user, leverage a second authentication reference to create new user accounts:
var config = {apiKey: "apiKey", authDomain: "projectId.firebaseapp.com", databaseURL: "https://databaseName.firebaseio.com"}; var secondaryApp = firebase.initializeApp(config, "Secondary"); secondaryApp.auth().createUserWithEmailAndPassword(em, pwd).then(function(firebaseUser) { console.log("User " + firebaseUser.uid + " created successfully!"); // Optional: Sign out from secondary authentication secondaryApp.auth().signOut(); });
Explanation
By establishing a separate authentication reference, the admin can operate on the platform without affecting the primary authentication session.
Note:
Remember that writing data to Firebase should be performed using the appropriate authentication reference, ensuring correct permissions for both the admin and the newly created user.
The above is the detailed content of How Can I Create Firebase User Accounts Without Signing Out the Current User?. For more information, please follow other related articles on the PHP Chinese website!