Handling cookies with Kaito
Kaito removed all cookie-related functionality in v3. It’s easy to reimplement, and we suggest you do this inside of your context.
Example
We recommend using the package cookie
. It’s simple and has a tiny footprint & zero dependencies.
bun i cookie
import {serialize, parse, type SerializeOptions} from 'cookie';
export const {getContext, router} = createUtilities(async (req, res) => {
return {
req,
res,
get cookies() {
const header = req.headers.get('cookie');
return header ? parse(header) : {};
},
setCookie(name: string, value: string, options: SerializeOptions) {
res.headers.set('Set-Cookie', serialize(name, value, options));
},
};
});