Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix: set apollo-token cookie in SSR #358

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from

Conversation

hauptbenutzer
Copy link

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.

  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.
@japboy
Copy link

japboy commented Dec 18, 2020

any updates here?

@hauptbenutzer
Copy link
Author

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.

@emmanuelvlad
Copy link

no more maintainers?

@kukosek
Copy link

kukosek commented Mar 25, 2021

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
Copy link

kukosek commented Mar 25, 2021

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

@mrcsmcln
Copy link

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

@truesteps
Copy link

truesteps commented Feb 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cookies not sent in SSR mode
7 participants