feathers.js V5 如何在不使用身份验证钩子的情况下检查用户是否登录

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

如何检查用户是否已登录 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: []}
})
}
javascript feathersjs feathers-authentication feathers-hook
© www.soinside.com 2019 - 2024. All rights reserved.