Closed maotora closed 7 years ago
Hi, your stack trace looks like the error originates from koa-better-body
and not form koa-passport
, which is probably this line:
app.use(convert(body({
multipart: true,
})));
@rkusa I removed the whole app.use(body())
statement, but i still receive the error.
Here is the message
TypeError: next is not a function
at attempt (/home/user/Projects/koa/test-project1/node_modules/passport/lib/middleware/authenticate.js:173:32)
at authenticate (/home/user/Projects/koa/test-project1/node_modules/passport/lib/middleware/authenticate.js:349:7)
at dispatch (/home/user/Projects/koa/test-project1/node_modules/koa-compose/index.js:44:32)
at /home/user/Projects/koa/test-project1/node_modules/koa-compose/index.js:36:12
at /home/user/Projects/koa/test-project1/node_modules/koa-better-router/index.js:544:46
at dispatch (/home/user/Projects/koa/test-project1/node_modules/koa-compose/index.js:44:32)
at /home/user/Projects/koa/test-project1/node_modules/koa-compose/index.js:36:12
at Server.<anonymous> (/home/user/Projects/koa/test-project1/node_modules/koa/lib/application.js:135:7)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:547:12)
at HTTPParser.parserOnHeadersComplete(_http_common.js:99:23)
I think i also forgot to mention that when i requireSignIn
from the route it goes to the next handler and no such error is emited.
const requireSignIn = passport.authenticate('local', { session: false });
router.post('/login', signIn); //- removing requireSignIn, handler signIn gets called!
Something must be wrong in my codebase.
I rewrote everything and it now works..
Thank you for your help. I will update if i understand the problem.
@maotora Well, the reason is you require the passport
lib instead of koa-passport
. 😅
I had the same typo too.....
import passport from 'passport'
app.use(passport.initialize())
app.use(passport.session())
Will throw the flowing error:
TypeError: next is not a function
at initialize (/home/xmrg/workspace/indwar/server/node_modules/passport/lib/middleware/initialize.js:53:5)
at dispatch (/home/xmrg/workspace/indwar/server/node_modules/koa-compose/index.js:44:32)
at next (/home/xmrg/workspace/indwar/server/node_modules/koa-compose/index.js:45:18)
at createGenerator (/home/xmrg/workspace/indwar/server/node_modules/koa-convert/index.js:24:16)
at createGenerator.next (<anonymous>)
at onFulfilled (/home/xmrg/workspace/indwar/server/node_modules/co/index.js:65:19)
at /home/xmrg/workspace/indwar/server/node_modules/co/index.js:54:5
at Object.co (/home/xmrg/workspace/indwar/server/node_modules/co/index.js:50:10)
at Object.toPromise (/home/xmrg/workspace/indwar/server/node_modules/co/index.js:118:63)
at next (/home/xmrg/workspace/indwar/server/node_modules/co/index.js:99:29)
You should change import passport from 'passport'
to import passport from 'koa-passport'
@tiaod lol Thank You, You are right, when I rewrote everything it worked!
I must have import'ed 'koa-passport' the second time and I didn't know what solved that.
Good Catch!
Hi, awesome middleware!
I'm getting that error when i use local-strategy with this middleware.
The examples work perfectly but i get these errors when i use it by myself. Here is my code.
and in my routes i have ..
The
requireSignIn
is the one called first andsignIn
won't even get called when that error fires!what's interesting is i've tried to replace
local
inwith
and i get the very same error message!
It's like my local-strategy won't get recognized for some reason.
Stack Trace
Thank You.