Skip to content

Commit

Permalink
FIX with-apollo-auth example token access (#4771)
Browse files Browse the repository at this point in the history
in some cases access to the token doesn't work in client side. this access to the token once in getInitialProps method and pass it down using props
  • Loading branch information
zapaiamarce authored and timneutkens committed Sep 12, 2018
1 parent 932e72b commit ae7e532
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/with-apollo-auth/lib/withApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export default App => {

static async getInitialProps(ctx) {
const { Component, router, ctx: { req, res } } = ctx
const token = parseCookies(req).token
const apollo = initApollo({}, {
getToken: () => parseCookies(req).token
getToken: () => token
})

ctx.ctx.apolloClient = apollo
Expand Down Expand Up @@ -69,7 +70,8 @@ export default App => {

return {
...appProps,
apolloState
apolloState,
token
}
}

Expand All @@ -78,7 +80,7 @@ export default App => {
// `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
getToken: () => props.token
})
}

Expand Down

0 comments on commit ae7e532

Please sign in to comment.