Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If you call setCookie twice, it will only set the last cookie #84

Closed
JosephCarrington opened this issue Nov 6, 2018 · 8 comments
Closed
Assignees
Labels

Comments

@JosephCarrington
Copy link

export function setCookie(ctx = {}, name, value, options = {}) {
  if (ctx && ctx.res) {
    ctx.res.setHeader('Set-Cookie', cookie.serialize(name, value, options))
  }

  if (process.browser) {
    document.cookie = cookie.serialize(name, value, options)
  }

  return {}
}

@dougwilson
Copy link
Contributor

I'm not sure how the code in this module would be able to fix that issue. The only thing it looks like you are calling from this module is the cookie.serialize function? Any thoughts on what changes we can make / would you be willing to make a pull request?

@JosephCarrington
Copy link
Author

Well specifically

getInitialProps({ctx}) {
  setCookie(ctx, 'foo', 'bar');
  setCookie(ctx, 'bar', 'baz');
}

will only set the bar cookie

@JosephCarrington
Copy link
Author

If I come up with a solution I'll happily make a PR

@dougwilson
Copy link
Contributor

Yea, but I mean are you sure the bug is in this lib or your code you posted? All this module is doing in your code is producing a string.

@JosephCarrington
Copy link
Author

So how would you go about setting two separate cookies?

@dougwilson
Copy link
Contributor

So I'm a bit unfamiliar with what the ctx.res.setHeader comes from. Each Set-Cookie is a separate header. Does that API allow setting the same header name with multiple values? Or is there a different API to use?

@JosephCarrington
Copy link
Author

OMG I'm so sorry. This was supposed to be on the 'nookies' github. Sorry sorry sorry

@dougwilson dougwilson self-assigned this Nov 7, 2018
@dougwilson
Copy link
Contributor

Oh, I see now. What you pasted above was just the code from the nookies source 😆

https://github.com/maticzav/nookies/blob/master/src/index.js#L16-L26

It's no problem at all!

@jshttp jshttp deleted a comment from revskill10 Dec 31, 2018
@jshttp jshttp locked as resolved and limited conversation to collaborators Dec 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants