Commit ae7e5323 authored by Marcelo Zapaia's avatar Marcelo Zapaia Committed by Tim Neutkens

FIX with-apollo-auth example token access (#4771)

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
parent 932e72b9
......@@ -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
......@@ -69,7 +70,8 @@ export default App => {
return {
...appProps,
apolloState
apolloState,
token
}
}
......@@ -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
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment