Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Users are occasionally Logged Out

Aperta
#97 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
firebase, javascript

Direzione di ricerca

Inizia da Firebase.js, index.js, FirebaseContext.js e dal componente Auth, seguendo l’istanza Firebase attraverso onAuthStateChanged e la ricerca nel Realtime Database. Riproduci il comportamento di logout o PERMISSION_DENIED e ispeziona in quel momento lo stato dell’autenticazione e del database. Il lavoro è completato quando viene identificata una causa riproducibile e viene documentata o implementata una correzione verificata, ma l’issue non fornisce test né criteri di accettazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
JavaScript
Stelle
1.3k
Fork
246
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/firebaseui-web-react

Tutte le issue di firebase/firebaseui-web-react

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.