1.0.4 • Published 2 years ago
enn-egg-jwt v1.0.4
egg-enn-egg-jwt
基于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.