【问题标题】:Logout error with conditional collection on React Firebase appReact Firebase 应用程序上的条件收集注销错误
【发布时间】:2019-03-16 16:43:52
【问题描述】:

在我的 Navbar.js 组件上,我有一个条件元素,仅当您是站点管理员时才会显示。如果满足条件,您会看到链接,您可以导航到该页面。但是,当我注销时,我得到一个错误:

未捕获的 FirebaseError:函数 Query.where() 需要有效的第三个 参数,但它是未定义的。

我认为正在发生的事情是系统正在注销用户,而导出默认值中的其余代码正在完成,它注意到 props.auth.uid 不存在。关于正在发生的事情还有其他想法吗?有人可以帮我解决它。提前谢谢...

// SiteAdministrators.js Component showing database query
const mapStateToProps = (state) => {
  const auth = state.firebase.auth

  return {
    messages: state.firestore.ordered.messages,
    siteAdmin: state.firestore.ordered.siteAdministrators,
    auth: auth
  }
}

export default compose(
  connect(mapStateToProps),
  firestoreConnect(props => {
    return [
        { collection: 'messages', where: [['replied', '==', false]] },
        { collection: 'siteAdministrators', where: [['pilotId', '==', props.auth.uid]]}
      ]
  })
)(SiteAdministrator);

// NavbarLinks.js Component showing logout function
const mapDispatchToProps = (dispatch) => {
  return {
    logout: () => dispatch(logout())
  }
}

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  firestoreConnect(props => {
    return [
        { collection: 'siteAdministrators' }
      ]
  })
)(LoggedInLinks)

【问题讨论】:

  • 我目前的想法是我应该只加载所有数据并让filtermap 函数只显示相关的内容,但我觉得这是一种较慢的方法。

标签: reactjs firebase react-redux react-redux-firebase


【解决方案1】:

我尝试向 where 查询添加条件。我不确定这是否正确,但它目前正在工作。请让我知道这是否是可接受的编程。

export default compose(
  connect(mapStateToProps),
  firestoreConnect(props => {
    return [
        { collection: 'messages', where: [['replied', '==', false]] },
        { collection: 'siteAdministrators', where: [['pilotId', '==', props.auth.uid || null]]}
      ]
  })
)(SiteAdministrator);

【讨论】:

    猜你喜欢
    • 2021-08-08
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    • 2019-04-21
    • 2018-07-08
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多