Handling cookies with Kaito
Kaito removed cookie serialization in v3. It’s easy to reimplement, and we suggest you do this inside of your context.
Example
While you do not need to follow this 1:1, we do recommend the package cookie
for its simplicity and package size.
import {serialize, parse, type SerializeOptions} from 'cookie';
export const {getContext, router} = createUtilities(async (req, res) => {
return {
req,
res,
get cookies() {
const header = req.headers.cookie;
return header ? parse(header) : {};
},
setCookie(name: string, value: string, options: SerializeOptions) {
res.setHeader('Set-Cookie', serialize(name, value, options));
},
};
});