如果您查看官方羽毛认证插件的默认选项,它说应该有一个用户对象在hook.params.user中可用(在实体选项下)成功羽毛js认证后,hook.params.user不存在
https://github.com/feathersjs/feathers-authentication
{
path: '/authentication', // the authentication service path
header: 'Authorization', // the header to use when using JWT auth
**entity: 'user', // the entity that will be added to the request, socket, and hook.params. (ie. req.user, socket.user, hook.params.user)**
service: 'users', // the service to look up the entity
passReqToCallback: true, // whether the request object should be passed to the strategies `verify` function
session: false, // whether to use sessions
cookie: {
enabled: false, // whether the cookie should be enabled
name: 'feathers-jwt', // the cookie name
httpOnly: false, // whether the cookie should not be available to client side JavaScript
secure: true // whether cookies should only be available over HTTPS
},
jwt: {
header: { typ: 'access' }, // by default is an access token but can be any type
audience: 'https://yourdomain.com', // The resource server where the token is processed
subject: 'anonymous', // Typically the entity id associated with the JWT
issuer: 'feathers', // The issuing server, application or resource
algorithm: 'HS256', // the algorithm to use
expiresIn: '1d' // the access token expiry
}
}
我有一个成功的验证,我有存储在一个window.localStorage JWT令牌。我只是不知道如何添加以获得hook.params.user对象出现。我需要在服务器端设置一些东西吗?我目前的身份验证流程只是文档设置的示例。
我目前的怀疑是这是遗留信息,因为新文档没有提到hook.params.user对象可用,我认为它只是使用钩子来插入用户标识。
https://docs.feathersjs.com/api/authentication/client.html
如果是这样的话,有没有办法只是为了让登录的用户当前的用户ID不使用钩子将其添加吗?
感谢
啊完美。我没有意识到每次打开应用程序时都必须调用app.authenticate。我看到用户对象现在被添加。 – Irlanco