apollo
apollo copied to clipboard
WIP: fix: set apollo-token cookie in SSR
This fixes #312.
This PR's description and its content are WIP. We need to figure out whether we want the implicit dependency on cookie-universal-nuxt
or if there's a different solution.
Prior to this, the used cookie library only supports setting cookies in SSR, if it is explicitly called in a middleware. So instead of doing this manually, usage of cookie-universal-nuxt is introduced. It is assumed to be present in the nuxt context.
any updates here?
I'm waiting for feedback on the introduction of the cookie-universal-nuxt
peer dependency. If that's fine for the maintainers, I'll update the docs and this MR accordingly.
no more maintainers?
Hello, pls fix this somehow :( Or is there a workaround being used? Like what's the point of Nuxt when I can't even server render user dependent content based on session cookie
I tried, but in nuxt console i get: Error Network error: Cannot read property 'get' of undefined
And when I disable prefetch in apollo queries, in browser console is this:
Network error: $cookies is undefined 2 apollo-module.js:112:15
Does this mean Apollo doesn't work for SSR apps that require auth? I'm unable to send cookies while in SSR mode.
@hauptbenutzer any idea how to implement cookie-universal-nuxt with a custom apolloConfiguration with a setContext or httpLink?
I tried sending cookie: $cookies.getAll({parseJSON: false})
but no cookies are sent...
nuxtjs 2.16.0 nuxt-apllo 4.0.1-rc.5
- custom client configuration with custom httpLink and custom setContext
const ssrMiddleware = setContext((_, { headers }) => ({
headers: {
...headers,
Accept: 'application/json',
'Content-type': 'application/json',
'X-Brand': 'some-brand',
'X-XSRF-TOKEN': decodeURIComponent($cookies.get('XSRF-TOKEN')),
},
}));
const httpLink = new HttpLink({
uri: `${$config.apiUrl}/graphql`,
credentials: 'include'
});
const link = from([ssrMiddleware, httpLink]);