FeathersJs: context.params.user在钩子前返回未定义的内容

问题描述 投票:0回答:1

当我尝试将 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个回答
0
投票

我能够通过将这个问题修复。authenticate 钩前 processProperty 钩子,如下图所示.我认为这是因为数组中的每个钩子都是从左到右处理的,所以在这种情况下,在数组中的 processProperty 钩子需要访问经过认证的用户,所以它需要在下面的 authenticate 钩子已被处理。

  before: {
...
    create: [authenticate('jwt'), processProperty()],
...
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.