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
SSR not passing cookies #186
Comments
@MrTeapot Thank you for raising this issue, This module is supposed to proxy cookies in SSR by default but, it seems there might be a bug in it's current implementation that foregoes this expected behavior when your client isn't declared in the |
@MrTeapot Update |
Thanks for getting back to me! I upgraded but I still have issues. |
I changed my middleware to this, now I don't get the warning I just mentioned. But still, the request in unauthorized:
This is from the nuxt config:
The Nuxt app is reached through http://nginx/ so they are on the same domain. |
@MrTeapot The As for the authorization issue here, I can confirm that the implementation does in fact work as it's expected to, so there must be something else at play here causing your auth issue, Might I ask what GraphQL API you're working with? |
I can see that the cookie is passed along now! So your library is doing what is expected :) The graphql api is built with Nestjs, and uses the express-session npm package for session management.
For some reason it's not picking up the session, even though the correct cookie is passed! |
From what I can see it looks like the nuxt ssr mode gets it's own session id and cookie. When the graphql queries run in SPA mode, it's the cookie id and session associated with the user. But when it runs in SSR mode, it's a different cookie and session id that is not associated with a user. |
@MrTeapot I am finding the same thing. Console logging out the gqlState in my server middleware shows the correct headers but my GraphQL API receives another. Although it seems like they are old tokens which suggest some persistence bug in the gqlState? |
Yup it looks like old cookies are showing up sometimes! I'm even getting new session id's assigned to old cookies in my graphql api.. I'm super confused right now :) There could also be some issues when logging out, I'm destroying the session and clearing the cookie but it's could still be stored in Nuxt. SSR appears to be using the old one, for the session that has been destroyed. |
@Diizzayy is it possible to override headers per request rather than relying on gqlState, similar to $fetch? |
@sweetroll headers can be overridden on a per request basis as seen here const variables = {}
const headers = { 'X-Custom-Header': 'ABC' }
const data = await GqlExample(variables, headers) |
@Diizzayy appreciate your quick reply. That definitely seems to be working better however I'm seeing an issue when trying to unset the Authorization header. When I pass |
@sweetroll Passing @sweetroll Feel free to reach out to me on discord@ Diizzayy#1964 , I may be able to provide more assistance there. |
Closing for now as the initial issue raised should be fixed in recently released versions |
Hey!
This is probably an issue based on my lack of knowledge about Nuxt. But I can't find a way to solve it.
I have a Nuxt middleware that makes sure that a user is authenticated before allowing them to navigate to certain pages. The authentication is based on sessions, and a cookie needs to be sent with every request to my graphql api.
This works great in SPA mode: the cookie is passed directly from the browser to the API. However, on initial page load, when the app runs in SSR mode, the cookie is not passed along to the API. This means that if a user logs in and navigates to a restricted page, then refreshes the window, they are redirected to the login screen even though they have a session.
How can I make sure that the SSR code passes along the cookie?
Here is the code for the middleware:
Thanks in advance.
The text was updated successfully, but these errors were encountered: