I’m using “@apollo/experimental-nextjs-app-support/ssr” in Next App router, in some “use client” components and trying to interface with my Keystone backend server.
I know the sign in mutation works because it returns the User object and I can view it in the Apollo Cache, however, although it creates a session cookie, Apollo does not seem to be sending the session cookie to the serverside when I try to authenticate the user.
I believe the
credentials: "include"
flag is what enables sending out headers/cookies right? Maybe I put it in the incorrect place or misconfigured it? Since I’m using this with Nextjs 13, I used the experimental-nextjs-app-support package, which I’m less familiar with so could it be that I misconfigured something there?
The credentials option in the ApolloClient constructor is there for convenience. ApolloClient will instantiate a new link if there’s none provided. That’s where the credentials option comes in handy:
Since you’re passing a link to the constructor, try moving credentials: "include" to the HttpLink options:
const httpLink = new HttpLink({
uri: "http://localhost:3000/api/graphql",
credentials: "include",
});
In the case of server components you would have to take the cookies off the incoming request by calling cookies() and then manually add them to the outgoing request.
Next.js doesn’t “forward” headers for you for anything happening on the server.