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)
});
Description
Currently the
cookies-nextlibrary supports passing a customencodefunction insetCookie, allowing users to control how cookie values are serialized before they're stored. However, there is no corresponding option to define a customdecodefunction ingetCookieandgetCookies, which makes handling non-standard serialised cookies or legacy formats more cumbersome.Use case
Proposal
Add support for an optional
decodecallback ingetCookieandgetCookies- similar to theencodeoption insetCookie. For example: