apollo icon indicating copy to clipboard operation
apollo copied to clipboard

WIP: fix: set apollo-token cookie in SSR

Open hauptbenutzer opened this issue 3 years ago • 7 comments

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.

hauptbenutzer avatar Oct 02 '20 17:10 hauptbenutzer

any updates here?

japboy avatar Dec 18 '20 11:12 japboy

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.

hauptbenutzer avatar Dec 18 '20 11:12 hauptbenutzer

no more maintainers?

emmanuelvlad avatar Jan 20 '21 21:01 emmanuelvlad

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

kukosek avatar Mar 25 '21 11:03 kukosek

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

kukosek avatar Mar 25 '21 11:03 kukosek

Does this mean Apollo doesn't work for SSR apps that require auth? I'm unable to send cookies while in SSR mode.

mrcsmcln avatar Aug 11 '21 15:08 mrcsmcln

@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]);

truesteps avatar Feb 08 '23 15:02 truesteps