SSR server forwarding cookies to apollo server?See original GitHub issue
This is a following issue from https://github.com/Akryum/vue-apollo/issues/400.
I am using
vue-cli-plugin-ssr together with
vue-cli-plugin-apollo and try to achieve proper SSR which prefetch data from the apollo server according to the authentication jwt from cookie.
My ssr server runs on
localhost:8000 and apollo server runs on
After using cookie instead of http request headers to pass the jwt to the ssr server, I can see the cookie is successfully passed to the ssr server:
But when the ssr server prefetches from the apollo server via its own http request, I can see it passes no cookie to it, therefore the prefetch is still no properly authenticated.
So now the problem is how to forward this cookie from the ssr server to the apollo server. The source code creating the ssr server here (https://github.com/Akryum/vue-cli-plugin-ssr/blob/master/lib/server.js#L4-L21) provides no interface to inject express middleware like
cookie-parser, and I also couldn’t find a way to export from here the express
req object, which I believe is necessary in my
entry-server.js file to customize the server-side
Any suggestions about that?
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
When I have some spare time 😸
@beeplin @zickat I’m having a similar issue trying to achieve proper ssr using
vue-cli-plugin-ssr. Obviously it’s using localstorage by default which I have overridden in
getAuth option, so that is using cookies now… My confusion is how to then ‘customize’ apolloProvider inside
entry-server.js to use the jwt from the cookie? I’ve found very little information outside of this ticket and the one other linked ticket about this although it seems it would be a common use case in ssr. Many thanks if someone can please elaborate a bit on how to achieve this.