Open pantuchy opened 4 years ago
Maybe specify the route for signin before declaring this middleware. The order of declaring routes and middlewares is important.
Another possibility is to declare different routers for your different concerns. In a specific router, Koa-router won't execute a middleware if there's no matching route. (I'd like to change this behavior in #44 though).
Maybe specify the route for signin before declaring this middleware. The order of declaring routes and middlewares is important.
But if I will declare /signin route before declaring middleware, then middleware guard.user.passport('local')
and controller will execute before validation middleware, am I right? If yes, then this is not, what I am expecting, because validation middleware should execute first, and only if validation succeeds, only then should run the rest middleware chain. With this approach I prevent unnecessary database queries to database, until validation will be successful.
Another possibility is to declare different routers for your different concerns. In a specific router, Koa-router won't execute a middleware if there's no matching route. (I'd like to change this behavior in #44 though).
Thank you for your advise, will think about it, may be it will be a solution.
I haven't worked with passport since ages so I can't advise more :-)
I haven't worked with passport since ages so I can't advise more :-)
Passport is just another middleware as well as controller 🙂
I've just found https://github.com/Foxandxss/koa-unless that might be interesting for your use case.
Another possibility is to declare different routers for your different concerns. In a specific router, Koa-router won't execute a middleware if there's no matching route. (I'd like to change this behavior in #44 though).
@julienw I really need this behaviour, how do I achieve this. I am using different auth middleware in different routers and all of them get called for some reason. see https://github.com/koajs/router/issues/90#issuecomment-660499700
The problem in #90 is that both routes match the first middleware, so the behavior I'm mentioning doesn't work for this case. What seems to work though is reversing the order of your routes. I'll leave a message in the other issue.
node.js version: v10.16.3
npm/yarn and version: 6.13.4
@koa/router
version: 8.0.5koa
version: 2.11.0Code sample:
Expected Behavior:
Expected, that route '/' will effect exactly for route '/', when using:
router.use([ '/signout', '/', '/update', '/password/change', '/email/change/request' ], guard.user.passport('jwt'), guard.csrf())
So that passport middleware should run exactly on those routes, which are is this array.Actual Behavior:
Unfortunately route '/' in the array of routes above effects on any other route, even on
'/signin'
, which is not in array for passport middleware.Additional steps, HTTP request details, or to reproduce the behavior or a test case: