matthewmueller / next-cookies

Tiny little function for getting cookies on both client & server with next.js.
368 stars 17 forks source link

JSON encoded values are automatically parsed? #26

Closed cullylarson closed 4 years ago

cullylarson commented 4 years ago

I have a cookie whose value is a JSON encoded string. When I retrieve the cookie using next-cookies, I get an object instead of a string. I wouldn't expect the JSON string to be parsed automatically, and it doesn't seem to be documented.

Cookies header is set to: blah=%7B%22foo%22%3A%22asdf%22%7D

Expected nextCookie to return:

{
  blah: '{"foo":"asdf"}'
}

Instead got:

{
  blah: {
    foo: "asdf"
  }
}
nfriedly commented 4 years ago

Hi, sorry for the confusion and the delay. This behavior can be disabled by passing an options object like so:

const allCookies = cookies(ctx, {doNotParse: true});

I'll update the readme to document this.