hook.params.user feathers js认证成功后不存在

hook.params.user does not exist after successful feathers js authentication

如果你查看官方的 feathers-authentication 插件的默认选项,它说 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 对象可用,我认为它只是使用挂钩来插入用户 ID。

https://docs.feathersjs.com/api/authentication/client.html

如果是这种情况,有没有办法只获取当前登录用户的用户 ID 而无需使用挂钩将其添加进去?

谢谢

它仍在添加中,但您必须使用存储中的令牌对套接字连接或 HTTP 请求进行身份验证。这通常通过调用 client.reAuthenticate() (with no parameters) on the client before making any other service calls. To see it in action, have a look at the JS chat frontend.

来完成