jwt.js 392 B

123456789101112131415161718
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const jwt = require('jsonwebtoken');
  4. // jsonWebToken处理
  5. class JwtService extends CrudService {
  6. constructor(ctx) {
  7. super(ctx, 'jwt');
  8. }
  9. encrypt(data) {
  10. const { secret } = this.config.jwt;
  11. const token = jwt.sign(data, secret);
  12. return token;
  13. }
  14. }
  15. module.exports = JwtService;