Monday, 5 June 2017

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

If you look at the official feathers-authentication plugin's default options, it says there should be a user object available in hook.params.user (under entity option)

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
  }
}

I have a successful authentication and I have a jwt token stored in window.localStorage. I just have no idea how to add to get the hook.params.user object to appear. Do I need to set something up in server side? My current authentication flow is just the example set by the docs.

My current suspicion is that this is legacy information, since the new docs do not mention hook.params.user object being available, and I think it just uses hooks to insert the user id instead.

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

If this is the case, is there a way just to get the user id of the current logged in user without using a hook to add it in?

Thanks



via Irlanco

No comments:

Post a Comment