apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
358 stars 25 forks source link

Send credentials from SSR #290

Open sayandedotcom opened 3 weeks ago

sayandedotcom commented 3 weeks ago

Send credentials from here giving error

app/ApolloWrapper.jsx file like this this

I want to send Like this const httpLink = createHttpLink({ uri: "http://localhost:8000/graphql", credentials: "include", });

### Tasks
phryneas commented 2 weeks ago

That's unfortunately impossible, since in that moment you are on the server and the server has no knowledge about the cookies of your Browser.

You can forward cookies from the incoming request (that calls SSR) to the outgoing request that calls your api - but you have to do so manually.

Unfortunately, this is a multi-step process as in Next.js SSR, you don't have access to cookies. So you have to get the cookies in RSC, forward them as props to your ApolloWrapper component and then add them to the outgoing request.

When transporting cookies as props, ensure to encrypt them, as otherwise they would be readable in the browser, too. Patrick has created a great example for that over here: https://github.com/apollographql/apollo-client-nextjs/issues/281#issuecomment-2057927433