Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior middleware #85

Closed
shcoderAlex opened this issue Mar 2, 2017 · 2 comments
Closed

Strange behavior middleware #85

shcoderAlex opened this issue Mar 2, 2017 · 2 comments

Comments

@shcoderAlex
Copy link

I always thought that if my token isn't valid I can't get next middleware. Is it correct logic?!
But I'm using your middleware and it isn't working how I thought.

return JWT.verifyAsync(token, secret, opts)
      .then(isRevoked(ctx, token))
      .then(user => {
        ctx.state = ctx.state || {};
        ctx.state[opts.key] = user;
        if (opts.tokenKey) {
          ctx.state[opts.tokenKey] = token;
        }
      })
      .catch(e => {
        if (!opts.passthrough) {
          const msg = 'Invalid token' + (opts.debug ? ' - ' + e.message : '') + '\n';
          ctx.throw(401, msg);
        }
      })
      .then(next);

petkaantonov/bluebird#476
Do you know about it?

@sdd
Copy link
Collaborator

sdd commented Mar 2, 2017

It depends upon if you have opts.passthrough set. If opts.passthrough is truthy, then downstream middleware still gets executed but ctx.state does not get populated with the decoded token.

Are there any problems you are experiencing? If so, can you give code examples and I'll see if I can help.

@sdd
Copy link
Collaborator

sdd commented Mar 6, 2017

Closing due to lack of response.

@sdd sdd closed this as completed Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants