async/await passport-jwt custom handler
See original GitHub issueHi, I am using koa-router and koa-passport with passport-jwt. The problem is that every error thrown inside passport custom callback is not catched by parent middleware. Am I missing something or is this intended behaviour? Can you please provide example how this should work with async/await and koa2?
Best regards
privateRouter.get('/test', isAuthenticated, users.test)
async function authenticate(ctx, next) {
await passport.authenticate('jwt', { session: false }, async(user, userInfo) => {
await next() // when next middleware throws error it won't be catched by parent middleware
throw new Error() // this won't be catched by parent middleware
})(ctx, next)
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How can I make an async authenticate calls with passport- ...
I have a working implementation with passport-local-mongoose but would like to use async/await to keep things consistent, avoid nested ...
Read more >How To Implement API Authentication with JSON Web ...
This guide will walk you through how to implement authentication for an API using JWTs and Passport, an authentication middleware for Node.
Read more >Everything you need to know about the `passport-jwt` ...
Intro to jsonwebtoken and passport-jwt configuration; What about Angular? How does that handle JWTs? JWT Based Authentication Implementation ...
Read more >Async Await for Passport.js Authentication in Express.js
The goal of this blog post is for you to know exactly how to implement the LocalStrategy for PassportJS using async/await patterns in...
Read more >How to implement JWT authentication in NestJS
Now, let's implement a JSON web token to authenticate users into the application. ... Here, we implemented a passport-local strategy to ...
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 Free
Top 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

I understand, I have created minimal working example demonstrating issue here. Maybe later on I can provide pull request with suggested changes, when I find time to dig deeper. Meanwhile I am using this workaround if it can help anyone:
I have incorporated your fix, works perfectly. Awesome job, thanks :simple_smile: