reactjs - React Redux Firebase 在身份验证后刷新之前不加载道具
问题描述
用户登录后,除非用户刷新页面,否则不会加载道具,为什么会这样?
这是他们在登录后重定向到的仪表板,然后使用 mapstatetoprops/connect 从 Firebase 加载这些道具。
我一直在检查其他线程,但似乎与我的问题无关或接近修复它,任何帮助将不胜感激。
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { firestoreConnect, isLoaded, isEmpty } from 'react-redux-firebase'
import ProjectList from '../Projects/ProjectList'
import { compose } from 'redux'
import CreateProject from '../Projects/CreateProject'
import { Redirect } from 'react-router-dom'
import NavComponent from './NavComponent'
import MainSidebar from'./MainSidebar'
import SearchMain from './Search/SearchMain'
import Notifications from './Notifications'
class Dashboard extends Component {
state = {
admins: '',
isLoaded: false
}
render() {
const {projects, auth, profile, organisations, innerprojects, comments, notifications} = this.props;
const searchMain = auth.uid ? <SearchMain profile={profile} comments={comments} innerprojects={innerprojects} projects={projects}/> : null
const notificationMain = auth.uid ? <Notifications profile={profile} notifications={notifications} /> : null
if (!auth.uid) return <Redirect to='/signin' />
if (isLoaded(auth) || !isEmpty(auth)) {
return (
<>
{profile.email ? <NavComponent notifications={notifications} comments={comments} innerprojects={innerprojects} projects={projects} auth={auth} profile={profile}/> : null }
<div className="container project-details-container">
<div className="row home-header-row">
<MainSidebar projects={projects} profile={profile}/>
<div className="col-lg-9 dash-section section">
<div className="row">
<div className="col-md-10">
{searchMain}
</div>
<div className="col-md-2 notifications-col">
{projects? notificationMain : null}
<CreateProject admins={this.state.admins} organisations={organisations}/>
</div>
</div>
{this.props.projects? <ProjectList auth={auth} projects={projects} authID={auth.uid} profile={profile}/> : null }
</div>
</div>
</div>
</>
)
}else{
return <p>Loading</p>
}
}
}
const mapStateToProps = (state) => {
return {
projects: state.firestore.ordered.projects,
comments: state.firestore.ordered.comments,
innerprojects: state.firestore.ordered.innerprojects,
auth: state.firebase.auth,
profile: state.firebase.profile,
notifications: state.firestore.ordered.notifications,
organisations: state.firestore.ordered.organisations
}
}
export default compose(
connect(mapStateToProps),
firestoreConnect([
{ collection: 'projects', orderBy: ['createdAt', 'desc']},
{ collection: 'comments', orderBy: ['createdAt', 'desc']},
{ collection: 'innerprojects', orderBy: ['createdAt', 'desc']},
{ collection: 'organisations', orderBy: ['time', 'desc'] },
{ collection: 'notifications', limit: 5, orderBy: ['time', 'desc']}
])
)(Dashboard)
看起来他们的 state.firestore 有问题,state.firebase 正在正确提取数据。请看下面的截图,看看哪些道具正在加载,哪些没有。
解决方案
如果您有适当的安全规则,则应确保在附加任何侦听器之前加载身份验证。这在文档中的几个地方都有介绍,包括auth recipes 部分和queries部分
推荐阅读
- httprequest - wemos d1 mini 上的 micropython http 请求
- sqlite - SQLITE 声明 - 日期
- java - 使用 App Engine 和 Maven 生成 pom.xml 文件
- r - 为什么特征函数返回“要替换的项目数不是替换长度的倍数”?
- c++ - 使用源向量作为目标
- javascript - Node.js 存储要在多个模块之间使用的变量的最佳方式
- javascript - 无法读取未定义的属性“0” - 日期
- elixir - 在 Elixir 地图中 => 和 : 有什么区别?
- node.js - 使用 axios 处理我的 JSON 数据时遇到问题
- python - Python:从 .seg 文件中提取数据