Skip to content

Commit ae7e532

Browse files
zapaiamarcetimneutkens
authored andcommittedSep 12, 2018
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
1 parent 932e72b commit ae7e532

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎examples/with-apollo-auth/lib/withApollo.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export default App => {
2222

2323
static async getInitialProps(ctx) {
2424
const { Component, router, ctx: { req, res } } = ctx
25+
const token = parseCookies(req).token
2526
const apollo = initApollo({}, {
26-
getToken: () => parseCookies(req).token
27+
getToken: () => token
2728
})
2829

2930
ctx.ctx.apolloClient = apollo
@@ -69,7 +70,8 @@ export default App => {
6970

7071
return {
7172
...appProps,
72-
apolloState
73+
apolloState,
74+
token
7375
}
7476
}
7577

@@ -78,7 +80,7 @@ export default App => {
7880
// `getDataFromTree` renders the component first, the client is passed off as a property.
7981
// After that rendering is done using Next's normal rendering pipeline
8082
this.apolloClient = initApollo(props.apolloState, {
81-
getToken: () => parseCookies().token
83+
getToken: () => props.token
8284
})
8385
}
8486

0 commit comments

Comments
 (0)
Please sign in to comment.