【问题标题】:FeathersJs: context.params.user returning undefined in before hookFeathersJs: context.params.user 在钩子前返回 undefined
【发布时间】:2020-09-18 20:49:49
【问题描述】:

当我尝试将 user._id 分配给 before 挂钩中的实体时,我变得不确定。

钩子

module.exports = (options = {}) => { 
return async context => { 

const user = context.params.user;

context.data = {
...
      userId: user._id,
...
    };
return context; 
}; 
};

这是我的钩子寄存器

  before: {
...
    create: [processProperty(), authenticate('jwt')],
...
  }
}

【问题讨论】:

    标签: javascript express feathersjs feathers-authentication feathers-hook


    【解决方案1】:

    我能够通过将authenticate 钩子放在我的processProperty 钩子之前来解决这个问题,如下所示。 我认为这是因为数组中的每个钩子都是从左到右处理的,所以在这种情况下,processProperty钩子需要访问经过身份验证的用户,所以它需要在处理完authenticate钩子之后来。

      before: {
    ...
        create: [authenticate('jwt'), processProperty()],
    ...
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      相关资源
      最近更新 更多