[next-urql] Is it possible to share context data from server-side to client-side? #1145
-
Hi, I am building the Authentication for my application with JWT. Currently, the
Current my code example: // pages/index.js
withUrqlClient((ssrExchange, ctx) => {
const cookieHeader = process.browser
? document.cookie
: ctx.req.headers.cookie ?? '';
const {access_token} = cookieParse(cookieHeader);
return {
url: 'my-url',
fetchOptions: {
headers: {
...(access_token && {Authorization: `Bearer ${access_token}`}),
},
},
exchanges: ['my-exchange'],
};
}) How can I receive the if(process.browser) {
cookieHeader = ctx.cookieHeader;
} else {
cookieHeader = ctx.cookieHeader = ctx.req.headers.cookie;
}
console.log(cookieHeader); // should works |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Document.cookie should contain the same cookies as you are using on the server so you should be able to parse them on the client like that. I’ve personally used nookies for this before |
Beta Was this translation helpful? Give feedback.
Document.cookie should contain the same cookies as you are using on the server so you should be able to parse them on the client like that. I’ve personally used nookies for this before