You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need a reactive data source for loading & currentUser, so can't do globals.
Reusable query
Could do a withUser() HOC that provides them through graphql() to any component that needs it. All using default cache-first, and deduplication should combine them into one query, while also maintaining data.loading/loadingUser.
Pro: concise. Using Apollo store like the global variable it is
Con: how to incorporate loggingIn into loading? In the single-use withAuth, it's defined as: loading={loading || this.state.loggingIn}
Do you want to prevent prop drilling because of how stressful and confusing it can be in the long run? If yes, then just use the withUser HOC anywhere you need it.
// auth.jsconstfetchUserData=()=>apollo.query({query: USER_QUERY,fetchPolicy: 'network-only'})// fetch at pageload in case client is already logged infetchUserData()exportconstlogin=()=>{apollo.writeData({data: {loginInProcess: true}})auth0Login({onCompleted: e=>{apollo.writeData({data: {loginInProcess: false}})if(e){console.error(e)return}apollo.reFetchObservableQueries()fetchUserData()}})}exportconstlogout=()=>{auth0Logout()apollo.resetStore()}
Activity
unicodeveloper commentedon Jun 17, 2018
Hey @lorensr IMO, if you are using
withAuthonce, why make it at all? I'd rather not allow it to exist.One authentication service, like
Auth.jswith all the helpers needed can do the magic. Check this Auth Service file.And then comfortably bring in the
withUserHOC!lorensr commentedon Jun 17, 2018
unicodeveloper commentedon Jun 17, 2018
No, I don't. It's just a matter of trade-offs.
Do you want to prevent prop drilling because of how stressful and confusing it can be in the long run? If yes, then just use the
withUserHOC anywhere you need it.lorensr commentedon Aug 13, 2018
Okay, here's the plan! I'm liking it a lot. Lmk if you have any further thoughts @unicodeveloper @jeresig
loginInProcessstatus: apollo-link-statewithUser: cache-only HOCAnd then in components:
This simplifies
App.js/routing a lot and completely eliminates passing aroundlogin/logout/user/loggingIneverywhere.lorensr commentedon Aug 28, 2018
Turned out to be simpler—given deduplication and default
cache-firstfetch policy, there's no point to thefetchUserDataandfetchPolicy: 'cache-only'withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33
withAuth -> withUser, fixes #33