Strange behavior for passport.authenticate() function
See original GitHub issueHi there!
I’m trying koa-passport and discovered a strange behavior on passport.authenticate() function call.
This function does return next() and this breaks my actions sequence (see details below).
If I change return next() in koa-passport lib to return, everything works just fine (at least as I expect it to be).
Can anyone advice on this and help me to clarify if there is a bug or I’m just doing something wrong?
My example application code that makes output located at: https://gist.github.com/Brozish/69e8147f323bbb044f3efd21e5d0df2f
create file version.js and copy example application code
yarn init
yarn add koa koa-router koa-bodyparser koa-passport passport-jwt mongoose winston
node version.js
Query application with curl or similar tool to see output:
curl -X GET \
http://localhost:3000/users \
-H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjViZmQwNTYwYWZmZjcxMjBmOTBkZTY4NSIsImVtYWlsIjoiaXNzdWVAaXNzdWUuaXNzdWUiLCJpYXQiOjE1NDMzMDg2NTcsImV4cCI6MTU3NDg0NDY1N30.RuyTMiiZRS6j8XhWPzPSKL4jacn2aRnaWLQQ6K5z9F7aWQgBoehl-1eXddRy_QfSxRF4cILPUhSWa1PnK78ocg' \
-H 'cache-control: no-cache'
My application console output if koa-passport does return next() (wrong actions sequence):
- startAuth
- beforeKoaPassport
- jwtStrategy
- startGetUsers
- endGetUsers
- afterKoaPassport
- endAuth
My application console output if koa-passport does return (everything is OK):
- startAuth
- beforeKoaPassport
- jwtStrategy
- afterKoaPassport
- endAuth
- startGetUsers
- endGetUsers
Koa-passport lib code that breaks my app can be found at: https://github.com/rkusa/koa-passport/commit/116fa48e2ca0ee6ac362f8b91e44e8e52a4ef30a
git blame ./lib/framework/koa.js --date=short -L 14 116fa48e (rkusa 2015-11-20 149) return next()
My full application code: https://bitbucket.org/Brozish/node.js/src/master/
Any help on this subject would be appreciated. If this is a bug, I would be happy to make a pull request or being mentioned in commit with a fix.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
For those who don’t like this piece of code:
You can try something like this:
And then use it like this:
I was trying to find such solution for 5 hours. I guess i need to leave it here, maybe it will help somebody in the future.
Weird, my JWT strategy isn’t being executed. Maybe this is a fix?