firebase / firebase/firebaseui-web-react

Users are occasionally Logged Out

未关闭
#97 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
1.3k
派生
246
PR 合并指标
30 天内没有已合并 PR

描述

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(






,
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 the**react-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 (


{
Some code omitted here
}

);
}
}

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.

贡献指南

打开贡献指南

调研方向

从 Firebase.js、index.js、FirebaseContext.js 和 Auth 组件开始,跟踪 Firebase 实例经过 onAuthStateChanged 以及 Realtime Database 查询的过程。复现 logout 或 PERMISSION_DENIED 行为,并检查该时刻的身份验证状态和数据库状态。完成的标准是确定一个可复现的原因,并记录或实现经过验证的修复,但该 issue 未提供测试或验收标准。

由索引模型根据 Issue 内容生成。

评估

技术栈
firebase, javascript
领域
authentication, database
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。