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
Cookies not sent in SSR mode #312
Comments
Got more data on this error, from a custom error handler in the smart query:
|
Looked into this some more today. Almost certain that cookies are not being sent for the SSR request, only on the client side requests now. |
is there a fix to this? i've ran into same problem. |
@rivor We're currently running with the solution in #358 I opened the PR for reference just now. For this to work, you'll need to add https://www.npmjs.com/package/cookie-universal-nuxt separately, as described in their docs. |
@hauptbenutzer hey, thanks for the quick reply! i had troubles with this from yesterday and i know that this used to work before when i tested. But after i deployed an app, It strangely enough stopped working and then i downgraded to ^4.0.0-rc.3 version (i read somewhere that it might help) but still didn't fix the issue. And now when i tried to apply your PR, i had issues with the permissions and i ended up reinstalled node_modules and put back newest version and it started working without your PR, but i still do have cookies-universal-nuxt installed. Could that be the fix? |
The issue is still here in 2021. Have you guys figured out a workaround i could use? I just want the cookie client sent to nuxt server being passed to the apollo prefetch requests |
Is there any update on that? |
bump Any updates? Even if I attach them manually, they are just not being sent for whatever reason.... 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]); |
This issue is very old but this is still an issue with this library. In SSR mode the server simply doesn't send any cookies which is particularly annoying even if you don't use SSR because it cannot be disabled in dev (afaik). I figured out a workaround to this issue: export default defineNuxtPlugin(async (nuxtApp) => {
const { $apollo } = useNuxtApp();
$apollo.defaultClient.setLink(
from([
new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => {
if (import.meta.server) {
headers['cookie'] = useRequestHeader('cookie') ?? '';
}
return { headers };
});
return forward(operation);
}),
$apollo.defaultClient.link,
])
);
}); This uses apollo's setLink function to set config values at runtime, |
Version
v4.0.0-rc.19
Reproduction link
https://pyj86.sse.codesandbox.io
Steps to reproduce
If
httpLinkOptions.credentials = true
it seems theCookie
header is set when client side, but not when the SSR request is happening.Setup
nuxt.config.js
like so:And then in
apollo-config-default.js
Hard load to a public URL, like: https://pyj86.sse.codesandbox.io/
It works fine, browse to a private URL via a nuxt-link and it works fine.
Hard load into a private URL and it will give SSR node not matching server-rendered errors.
This page will only work if you are logged into backend. DM me for the logins which is here: https://stackhaus-backend.funkhaus.us /wp-admin
Public page: https://pyj86.sse.codesandbox.io/
Private page: https://pyj86.sse.codesandbox.io/featured/private-page
What is expected ?
Cookie header should be sent when both client side and SSR
What is actually happening?
SSR gives node not matching server-rendered errors
Additional comments?
I'm running WordPress as a headless CMS and trying to get preview/draft/private pages/posts working. The setup results in the backend having a different domain to your frontend, like
example.com
andapi.example.com
.The text was updated successfully, but these errors were encountered: