Home > Web Front-end > JS Tutorial > How Can I Create Firebase User Accounts Without Signing Out the Current User?

How Can I Create Firebase User Accounts Without Signing Out the Current User?

Barbara Streisand
Release: 2024-12-08 15:51:14
Original
277 people have browsed it

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();
});
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template