Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Users are occasionally Logged Out

Open
#97 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
firebase, javascript

Research direction

Start with Firebase.js, index.js, FirebaseContext.js, and the Auth component, tracing the Firebase instance through onAuthStateChanged and the Realtime Database lookup. Reproduce the logout or PERMISSION_DENIED behavior and inspect the authentication and database state at that point. Done means identifying a reproducible cause and documenting or implementing a verified fix, but the issue provides no test or acceptance criteria.

Written by the indexing model from the issue text.

Description

Hello guys, I am having a weird behavior where Firebase occasionally logs out my users

Here is how I am using Firebase

I have a file called Firebase.js where I configured my Firebase instance as below

import * as firebase from "firebase";

const firebaseConfig = {
    apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
    authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
    databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
    projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
    storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
    messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGE_SENDER_ID,
    appId: process.env.REACT_APP_FIREBASE_APP_ID,
    measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID
};

class Firebase {
    constructor() {
        this.firebase = firebase.initializeApp(firebaseConfig);
    }
}

export default Firebase;

I made this single instance of Firebase accessible to all my applications in my index.js file as below

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import * as serviceWorker from './serviceWorker';
import App from './pages/App';
import {BrowserRouter} from 'react-router-dom'
import Firebase from "./backend/configs/firebase";
import {FirebaseProvider} from "./contexts/FirebaseContext";

ReactDOM.render(
    <React.StrictMode>
        <FirebaseProvider value={new Firebase()}>
            <BrowserRouter>
                <App/>
            </BrowserRouter>
        </FirebaseProvider>
    </React.StrictMode>,
    document.getElementById('root')
);

serviceWorker.unregister();

Here is my FirebaseContext.js file

import React from "react";

const FirebaseContext = React.createContext(null);

export const FirebaseProvider = FirebaseContext.Provider; export const FirebaseConsumer = FirebaseContext.Consumer;

export default FirebaseContext;

Now I am using StyledFirebaseAuth from the thereact-firebaseui dependency as the way to log in my users as below

import * as React from "react";
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
import firebase from 'firebase';
import FirebaseContext from "../contexts/FirebaseContext";

export default class Auth extends React.Component {
    static contextType = FirebaseContext;

    constructor(props, context) {
        super(props, context);
        this.firebase = this.context.firebase;
        this.uiConfig = {
            // Popup sign in flow rather than redirect flow.
            signInFlow: 'popup',
            signInOptions: [{
                defaultCountry: 'NG',
                provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,
            }], callbacks: {
                // Avoid redirects after sign-in.
                signInSuccessWithAuthResult: () => false
            }
        };
        this.state = {
            loading: false
        }
    }

    // Listen to the Firebase Auth state and set the local state.
    componentDidMount() {
        let self = this;
        this.unregisterAuthObserver = this.firebase.auth().onAuthStateChanged(
            (user) => {
                if (user != null) {
                    this.setState({
                        loading: true
                    })
                    const userId = user.uid;
                    //Fetch in the details of the logged in user
                    firebase
                         .database()
                        .ref(USERS + "/" + userId)
                        .once('value')
                        .then(function (snapshot) {
                            if (snapshot.val()) {
                                //Code omitted here
                                window.location = DASHBOARD
                            } else {
                            }
                        }, function () {
                        });
                }
            });
    }


    // Make sure we un-register Firebase observers when the component un-mounts.
    componentWillUnmount() {
        this.unregisterAuthObserver();
    }

    render() {
        return (
           <div>
              {
              Some code omitted here
              }
          </div>
        );
    }
}

After a while I noticed that firebase keeps on logging out the logged in user out such that subsequent database calls fails with PERMISSION_DENIED.

This has wasted alot of my time. Any help would be greatly appreaciated.

Thank you.

Dominant language
JavaScript
Stars
1.3k
Forks
246
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebaseui-web-react

All issues in firebase/firebaseui-web-react

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.