Skip to content

Feature request: allow custom decode function in getCookie #108

@princekumar-d

Description

@princekumar-d

Description

Currently the cookies-next library supports passing a custom encode function in setCookie, allowing users to control how cookie values are serialized before they're stored. However, there is no corresponding option to define a custom decode function in getCookie and getCookies, which makes handling non-standard serialised cookies or legacy formats more cumbersome.

Use case

  • You may receive cookies from external services or older systems that use non-standard encodings (e.g., Base64, custom encodings).
  • Without a custom decoder, you must manually decode values after retrieving them, leading to boilerplate and inconsistent patterns.

Proposal

Add support for an optional decode callback in getCookie and getCookies - similar to the encode option in setCookie. For example:

getCookie('key', {
  req,
  res,
  decode: (value: string) => yourCustomDecoder(value)
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions