5

I don't know how to pass 'profile' or 'auth' props to firestoreConnect() function in order to query collections or documents based on user id or some other key (my code snippet is below).

i can access both 'auth' and 'profile' objects inside my jsx code but I can't find a way to use them in firestoreConnect() function (I'm getting an error: TypeError: Cannot read property 'uid' of undefined). if I hardcode some uid then all works fine but I can't pass it as props value.

any suggestion is highly appreciated!

export default compose(
  firebaseConnect(),
  firestoreConnect(props => [{ collection: 'projects', where: [['uid', '==', props.auth.uid]] }]), <<--THIS LINE DOES NOT WORK
  connect((state, props) => ({
    projects: state.firestore.ordered.projects,
    profile: state.firebase.profile,
    auth: state.firebase.auth,
  }))
)(Projects);
Lior Bar-On
  • 8,250
  • 3
  • 28
  • 41
user549385
  • 95
  • 8

2 Answers2

3

not sure why your code isn't working (its working for me). Have you tried console logging props inside the firestoreConnect? Like this:

export default compose(
    firebaseConnect(),
    firestoreConnect(props => {
        console.log(props)
        return [
            { collection: 'projects', where: [['uid', '==', props.auth.uid]] }
        ]
    }), 
    connect((state, props) => ({
        projects: state.firestore.ordered.projects,
        profile: state.firebase.profile,
        auth: state.firebase.auth,
    }))
)(Projects);

Perhaps that can get you on the right track.

Hope you solve it!

  • I think you need to put connect before firestoreConnect. so `firebaseConnect,connect,firestoreConnect`. – Ben W Mar 17 '20 at 11:55
1

You probably already solve this, but just post here if other people run into this. You need move your connect method before firestoreConnect, so something like this:

export default compose(
  firebaseConnect(),
  connect((state, props) => ({
    projects: state.firestore.ordered.projects,
    profile: state.firebase.profile,
    auth: state.firebase.auth,
  })),
  firestoreConnect(props => [{ collection: 'projects', where: [['uid', '==', props.auth.uid]] }]), <<--THIS LINE DOES NOT WORK
)(Projects);
Yi Zhou
  • 758
  • 6
  • 24