Extends pillarjs/cookies to adapt koa and egg with some additional features.
Encrypt
@eggjs/cookies provide an alternative encrypt mode like signed. An encrypt cookie’s value will be encrypted base on keys. Anyone who don’t have the keys are unable to know the original cookie’s value.
import { Cookies } from '@eggjs/cookies';
const cookies = new Cookies(ctx, keys[, defaultCookieOptions]);
cookies.set('foo', 'bar', { encrypt: true });
cookies.get('foo', { encrypt: true });
Note: you should both indicating in get and set in pairs.
import { Cookies } from '@eggjs/cookies';
const cookies = new Cookies(ctx, keys);
cookies.on('cookieLimitExceed', ({ name, value }) => {
// log
});
cookies.set('foo', longText);
@eggjs/cookies
Extends pillarjs/cookies to adapt koa and egg with some additional features.
Encrypt
@eggjs/cookiesprovide an alternativeencryptmode likesigned. An encrypt cookie’s value will be encrypted base on keys. Anyone who don’t have the keys are unable to know the original cookie’s value.Note: you should both indicating in get and set in pairs.
Cookie Length Check
Browsers all had some limitation in cookie’s length, so if set a cookie with an extremely long value(> 4093),
@eggjs/cookieswill emit ancookieLimitExceedevent. You can listen to this event and record.License
MIT
Contributors
Made with contributors-img.