Skip to content

Sharing cookies/data from middleware to server-side props #38650

Answered by icyJoseph
controversial asked this question in Help
Discussion options

You must be logged in to vote

Hi,

The request is immutable, so it arrives to the Node.js server without changes, that's why your cookie is missing.

What you can do is a bit of a magic trick... because you can read the response in getServerSideProps, and from there getHeader, called set-cookie.

export function getServerSideProps({ req, res }) {
  console.log('Cookie from accessToken:', context.res.getHeader('set-cookie'));
  return { props: {} };
}

And from there you just have to parse that cookie, and possibly remove it or let it through.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@colinclerk
Comment options

@controversial
Comment options

@sanderpick
Comment options

Answer selected by controversial
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
5 participants