error always null when using custom callback
See original GitHub issueThe code I have, (the signature is from http://passportjs.org/docs/authenticate)
passport.authenticate('jwt', { session: false }, (err, user, info) => {
if (err) {
return next(err);
}
if (!user) {
return next(AuthenticationError(401, info));
}
req.user = user;
return next();
})(req, res, next);
However, in the case of malformed jwt or expired jwt, the err
object is always null
while the info
object is carrying the error information.
Is this designed on purpose or should be a bug?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Callback Listener always returning null - java - Stack Overflow
I am trying to create a simple SMS library for Android for which i have created some custom listener. I want ...
Read more >ASPxGridView - The GetRowValues method returns null ...
I have an ASPxGridview which is bound at runtime on Page_Load. I am trying to add a custom callback button to create a...
Read more >The function always returns null : r/Kotlin - Reddit
I'm calling the functions doIfFailureWithResult and doIfSuccessWithResult , inside the async block. I had to manually return a boolean ...
Read more >AWS Lambda function handler in Node.js
The callback function takes two arguments: an Error and a response. When you call it, Lambda waits for the event loop to be...
Read more >Advanced Callbacks | Dash for Python Documentation | Plotly
Catching Errors with PreventUpdate ... In certain situations, you don't want to update the callback output. You can achieve this by raising a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This was pretty confusing for me. If an expired or invalid token is not an exception, what is?
Here’s the middleware I ended up with.
@LukeAskew I wrote this module using passport-local as a model.
In passport-local, which was written by the author of the passport framework, failure to authenticate is not treated as an exception. Instead, invalid credentials results in the strategy calling self.fail() (which populates info). I treat expired or invalid JWT’s the same way the passport-local strategy would treat an incorrect password or a non-existent user.
Based on my understanding of passport-local, only things like database errors, etc. result in exceptions. To me this makes sense since exceptions should be reserved for unexpected errors. Invalid auth credentials are an expected case for an authentication framework and not treated as an exception by this module or passport-local.