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

Give option getToken: null, but dont get error back #211

Open
huskylin opened this issue Nov 1, 2018 · 1 comment
Open

Give option getToken: null, but dont get error back #211

huskylin opened this issue Nov 1, 2018 · 1 comment

Comments

@huskylin
Copy link

huskylin commented Nov 1, 2018

const jwtAuth = expressJwt({
  secret: 'secretkey',
  credentialsRequired: false,
  getToken: function fromHeaderOrCookies (req) {
    if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
      return req.headers.authorization.split(' ')[1];
    } else if (req.cookies.JWT) {
      return req.cookies.JWT;
    }
    return null;
  }
}).unless({ path: ['/login']});

I copy example code and edit it to a "cookie version"
If browser have cookie, it will check and perfectly works.
If I delete cookie from the browser, it should return error but it doesn't.

It means: i give getToken a null value, it doesn't give a error back.
Where did I go wrong?

@huskylin
Copy link
Author

huskylin commented Nov 1, 2018

Ohhhh, I got it
Cuz I set credentialsRequired = false
so it wont show error
But I feel a little weird that "no token will be fine, but wrong token will get error".

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

1 participant