1

On my Navbar.js component I have a conditional element that only displays if you are an siteAdministrator. If the condition is met you are shown the link and you can navigate to the page. However, when I logout I get thrown an error:

Uncaught FirebaseError: Function Query.where() requires a valid third argument, but it was undefined.

What I think is happening is that the system is logging out the user and while the rest of code in export default is finishing it is noticing that props.auth.uid does not exists. Are there any other thoughts as to what is happening and could someone help me fix it. Thanks in advance...

// 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)
4

1 回答 1

1

I tried adding a condition to the where query. I am not sure this is correct but it is currently working. Please let me know if this is acceptable programming.

export default compose(
  connect(mapStateToProps),
  firestoreConnect(props => {
    return [
        { collection: 'messages', where: [['replied', '==', false]] },
        { collection: 'siteAdministrators', where: [['pilotId', '==', props.auth.uid || null]]}
      ]
  })
)(SiteAdministrator);
于 2019-03-16T17:04:15.353 回答