Skip to content

Unable to get httpOnly cookie inside getServerSideProps #37830

Answered by icyJoseph
kagithapk asked this question in Help
Discussion options

You must be logged in to vote

Hi,

I have a bunch of apps that do this, and it works flawlessly so I am gonna guess we are missing something here, as usual with cookies, you have to squint hard to see where the error is.

While I setup a reproduction demo, could you please try with setting a path to the cookie? with this value: /

Edit

Alright, just did some testing, and the Path must be set explicitly when using the cookie library, it is not set to / by default, which I think is ok, it is just common practice to set it as / - Do let me know if that change makes it work for you.

  res.setHeader(
    "set-cookie",
    serialize("tomato", "foo-bar", { path: "/", httpOnly: true })
  );

Here's a video by Feross, from his Web…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@kagithapk
Comment options

Answer selected by kagithapk
Comment options

You must be logged in to vote
4 replies
@TylerOlthuizen
Comment options

@gregg-cbs
Comment options

@milanpoudelwebdeveloper
Comment options

@naimulemon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
7 participants