目录

@eggjs/cookies

NPM version build status Test coverage npm download

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.

Browsers all had some limitation in cookie’s length, so if set a cookie with an extremely long value(> 4093), @eggjs/cookies will emit an cookieLimitExceed event. You can listen to this event and record.

import { Cookies } from '@eggjs/cookies';

const cookies = new Cookies(ctx, keys);

cookies.on('cookieLimitExceed', ({ name, value }) => {
  // log
});

cookies.set('foo', longText);

License

MIT

Contributors

Contributors

Made with contributors-img.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号