【问题标题】:Getting JWT object after authentication认证后获取 JWT 对象
【发布时间】:2018-06-17 09:28:39
【问题描述】:

我创建了一个使用feathers generate authentication 的身份验证和一个需要使用feathers generate service 进行身份验证的服务。

我根本没有对此进行任何代码更改。

所以我有以下内容:

app.service('authentication').hooks({
  before: {
    create: [
      authentication.hooks.authenticate(config.strategies)
    ],
    remove: [
      authentication.hooks.authenticate('jwt')
    ]
  }
});

我想知道,在成功验证 JWT 令牌之后,如何将该对象放入我的服务构造函数中?

在我的服务中,我有:

module.exports = {
  before: {
    all: [ 
      authenticate('jwt'),
      hook => { console.log(hook.params.payload); } 
    ],

哪个控制台记录了负载,但我只是不知道如何实际保存它以便我的服务可以访问它。

【问题讨论】:

    标签: javascript node.js jwt feathersjs


    【解决方案1】:

    如果你看一下params,我意识到它就在里面。

    class Service {
    
      constructor (options) {
        this.options = options || {};
      }
    
      async find (params) {
    
        console.log(params);
      ..
      .
    

    【讨论】:

      猜你喜欢
      • 2019-04-20
      • 1970-01-01
      • 2017-09-27
      • 2021-03-05
      • 2020-07-15
      • 1970-01-01
      • 2016-04-24
      • 2014-10-13
      • 2021-05-11
      相关资源
      最近更新 更多