[Passport] Custom callback in Passport Middleware for error handler
See original GitHub issueSome errors types as invalid signature, jwt expired, no auth token, invalid token, invalid algorithm… are not being handled on passport-jwt
The default response send only ‘unauthorized’ message and http status 401
In this Issue the author recommend using custom callbacks according to official passport docs
I’ve tried to try the following code, but I can not get it to work fine
export class AuthModule implements NestModule {
public configure(consumer: MiddlewaresConsumer) {
consumer
.apply(passport.authenticate('jwt', { session: false }, (err, user, info) => {
console.log(info.message)
}))
.forRoutes({ path: '/auth/authorized', method: RequestMethod.ALL });
}
}
console.log(info.message)
Is printed but does not can exit function, and within it next() function is not available, so response stays in the waiting forever
Any idea?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:21 (4 by maintainers)
Top Results From Across the Web
Express Passport (node.js) error handling - Stack Overflow
The strategy-implementation works in conjunction with passport.authenticate to both authenticate a request, and handle success/failure.
Read more >how to customize http response if failed authentication? #157
I have below code to use passport-jwt to verify user authentication. But it returns 500 internal error to the client if it failed ......
Read more >Documentation: Middleware - Passport.js
In this route, passport.authenticate() is middleware which will authenticate the request. By default, when authentication succeeds, the req.user property is set ...
Read more >How to use the passport.authenticate function in passport - Snyk
To help you get started, we've selected a few passport.authenticate examples, ... Otherwise, // authentication has failed. app.get('/auth/twitter/callback', ...
Read more >Authenticate Users With Node ExpressJS and Passport.js
Our application contains one POST route, /login. We are ready to make the authentication process work by creating this route. app.post('/login ...
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
hi,
you can access
next
like this.Hi @cdiaz, Just use class middleware, not the functional one.