1.0.4 • Published 2 years ago

enn-egg-jwt v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

egg-enn-egg-jwt

NPM version build status Test coverage David deps Known Vulnerabilities npm download

基于egg-jwt,集成了下redis,实现单独登录

Install

$ npm i enn-egg-jwt --save

Usage

// {app_root}/config/plugin.js
exports.ennEggJwt = {
  enable: true,
  package: 'enn-egg-jwt',
};
exports.ennEggJwt = { // 需要同时启用egg-jwt插件
  enable: true,
  package: 'egg-jwt',
};

Configuration

// {app_root}/config/config.default.js
exports.jwt = { // 对egg-jwt配置的新增
  secret: '123456',
  prefix: 'jwt:token:',
  expire: 3600,
};

see config/config.default.js for more detail.

Example

生成token,其中参数id为必须且唯一

const token = await app.jwtSingle.token({ id, account, from });

token校验

    try {
      const decode = await app.jwtSingle.check(token);
    } catch (error) { 
      app.logger.info(`[${ctx.requestId}] [jwt.verify error: ]`, error)
      throw error;
    }

Questions & Suggestions

Please open an issue here.

License

MIT

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago