Skip to content

Dynamically Set Access Token on Find, Get, Create, Remove Requests | Socketio | Rest | Feathers Client #2541

Answered by daffl
palmtown asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can do this dynamically by setting params.authentication before the authenticate('jwt') hook. In your case you would pull the access token from the query in a hook:

const setAuthentication = context => {
  const { accessToken, ...query } = context.params.query;

  context.params.authentication = {
    strategy: 'jwt',
    accessToken
  }
  // For subsequent requests, use the query without `accessToken`
  context.params = {
    ...context.params,
    query
  }
}

Then on the client you can do:

const results = await app.service("messages").find({
  query: {
    ...query,
    accessToken
  }
});

Keep in mind that Socket.io connections will still maintain a connection for the user tha…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@palmtown
Comment options

@palmtown
Comment options

Answer selected by palmtown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants