nicolaslopezj / meteor-apollo-accounts

Meteor accounts in GraphQL
MIT License
146 stars 37 forks source link

How to detect current user synchronously? #69

Open joncursi opened 7 years ago

joncursi commented 7 years ago

In my render function, I want to render a View depending on whether or not the user is signed in or not. You can do this synchronously via:

{currentUser &&
  <View>
    {...}
  </View>
}

How do you achieve this with meteor-apollo-accounts? The only thing I can find is userId, but that is an async value so it doesn't work in the above example. Thanks!

joncursi commented 7 years ago

The same goes for fetching data. In many components, I need to fetch data if there is a user signed in. However, if there is no user, I shouldn't fetch the data. However, again, recompose HOCs do not support async for good reasons.

joncursi commented 7 years ago

I'm not sure if this is the recommended way to do this, but my workaround for now is to store the tokens myself to my own Redux store:

    onTokenChange((tokenData) => {
      dispatch({
        payload: tokenData,
        type: UPDATE_USER,
      });
    });