Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass 'auth' or 'profile' object to firestoreConnect() with react-redux-firebase?

Tags:

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);
like image 726
user549385 Avatar asked Jan 30 '19 14:01

user549385


1 Answers

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!

like image 54
Björn Allvin Avatar answered Sep 29 '22 02:09

Björn Allvin