如何检查用户是否已登录 Feathers,似乎只有在使用身份验证挂钩时才会在上下文参数中填充用户。有没有办法像下面的find挂钩一样检查不受限制的路径。
export const messages = app => {
app.use('messages', new MessageService(getOptions(app)), {
methods: ['find', 'get'],
events: []
})
app.service('messages').hooks({
around: {
all: []
},
before: {
all: [],
// here the user is undefined even if request is done by a logged in user
find: [iff(isProvider('external'), async cxt => console.log(cxt.params.user))],
// here the user is defined since only logged in users can access it
get: [ authenticate('jwt'), iff(isProvider('external'), async cxt => console.log(cxt.params.user))],
},
after: {all: []},
error: {all: []}
})
}