with-apollo-auth
I need to refresh the page after performing login/register/logout to see the result.
Steps to reproduce the behavior, please provide code snippets or a repository:
yarn create next-app --example with-apollo-auth with-apollo-auth-appyarn devAfter login I should see the logged in page.
I think it's connected to this piece of code:
// Force a reload of all the current queries now that the user is
// logged in
client.cache.reset().then(() => {
redirect({}, '/')
})
It seems the reset is not performed, as I need to refresh the page to see the desired result (same with register, logout).
Taking redirect out of cache reset also doesn't make any change to the behavior.
Cache reset definitely does not reset the cache.
Redirect doesn't redirect from signin to index. It does redirect from index page when you logout though. However since cache is not reset, signin page redirects you back to the index page.
Seeing a related issue: After setting the cookies, I can only get data after manually refreshing the page. Redirects and/or cache resets don't do the trick.
@ghost and @okankayhan I also found the same behavior. I believe what is happening is withApollo.getInitialProps is responsible for providing the token to withApollo.ctor but since withApollo.getInitialProps does not re-run, the token is not provided in getToken(). Using the sample project, I replaced
constructor (props) {
super(props)
// `getDataFromTree` renders the component first, the client is passed off as a property.
// After that rendering is done using Next's normal rendering pipeline
this.apolloClient = initApollo(props.apolloState, {
getToken: () => props.token
})
}
With:
constructor (props) {
super(props)
// `getDataFromTree` renders the component first, the client is passed off as a property.
// After that rendering is done using Next's normal rendering pipeline
this.apolloClient = initApollo(props.apolloState, {
getToken: () => parseCookies().token
})
}
This seems to have fixed the issue.
Feel free to send a pull-request @zachariahtimothy
Roger that @timneutkens , I will fix that up today now that mine has been working for a while.
馃檶 Awesome!
Most helpful comment
@ghost and @okankayhan I also found the same behavior. I believe what is happening is withApollo.getInitialProps is responsible for providing the token to withApollo.ctor but since withApollo.getInitialProps does not re-run, the token is not provided in getToken(). Using the sample project, I replaced
With:
This seems to have fixed the issue.