@mahudas/jwt

0.0.2 • Public • Published

@mahudas/jwt

Dependencies

  • mahudas^0.0.9
  • jsonwebtoken^9.0.0

As a plugin

如同一般的plugin,透過npm安裝之後,在Application的plugin.env.js裡設定啟用。

npm i @mahudas/jwt -s
// config/plugin.deafult.js
module.exports = {
  jwt: {
    enable: true,
    package: '@mahudas/jwt',
  },
}

設定

// config/config.default.js
module.exports = {
  jwt: {
    sign: {}, 
    verify: {}, 
    decode: {},
  },
}
參數 說明
sign 可直接參考 jsonwebtoken.sign 的 Options 參數
verify 直接參考 jsonwebtoken.verify 的 Options 參數
decode 直接參考 jsonwebtoken.decode 的 Options 參數

Example

// controller.js or service.js or middleware.js
const token = await ctx.jwt.sign({foo: 'bar'}, 'secret');
const verify = await ctx.jwt.verify(token, 'secret');
const decode = ctx.jwt.decode(token);

其他例子可以參考 https://github.com/auth0/node-jsonwebtoken

Readme

Keywords

none

Package Sidebar

Install

npm i @mahudas/jwt

Weekly Downloads

1

Version

0.0.2

License

ISC

Unpacked Size

4.71 kB

Total Files

7

Last publish

Collaborators

  • ml-dev
  • ml-ash
  • ml-sherwin
  • d.kao
  • ml-jason