1.1.3 • Published 5 years ago

egg-jwt2 v1.1.3

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

egg-jwt2

NPM version build status Test coverage

Deepexi Egg's JWT(JSON Web Token Authentication Plugin)

Install

$ npm i egg-jwt2 --save

Usage

// {app_root}/config/plugin.js
exports.jwt = {
  enable: true,
  package: "egg-jwt2"
};

Configuration

// {app_root}/config/config.default.js
'use strict';
exports.jwt = {
  enable: true,
  // match和ignore不能同时使用
  match: '/login/1',
};

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

Example

// app/router.js
"use strict";

module.exports = app => {
  app.get('/test',app.controller.test.index);
 // if you want use middleware
  app.get('/test',app.middleware.jwt(),app.controller.test.index);
};
// app/controller/test.js
("use strict");

module.exports = app => {
  class SuccessController extends app.Controller {
    index() {
         console.log('query body : ', this.ctx.query);
         this.ctx.body = this.ctx.query;
    }
  }
  return SuccessController;
};

Questions & Suggestions

Please open an issue here.

License

MIT