Hello. Guards are executed after all middleware. Is it possible to make it the other way around? I have an auth middleware that checks if the session is valid. I have a rate limit guard. It doesn't make any sense to fetch the database and check if the session is valid, if the user is rate limited. The session checking part should not get executed.
#Guard and middleware order
12 messages · Page 1 of 1 (latest)
Could you make the auth middleware another guard? There's no way to change the order of enhancers so I'm looking at a different solution for you
I could do that, but how can I make sure that the throttler guard is executed before the auth one?
Global guards execute before all other guards
How do you bind them? APP_GUARD or useGlobalGuards?
APP_GUARD in app.module.ts
I'll try to use useGlobalGuards and put them in order, but not sure if that will break the throttler
yep, doesn't work that way
{
provide: APP_GUARD,
useClass: ThrottlerBehindProxyGuard
},
{
provide: APP_GUARD,
useClass: CheckSessionGuard
}
Found a solution, I just put them in order in app.module.ts like this. It works, thank you for the help
Ah, just saw this again, yeah was gonna mention that the order you add them to providers sets the order they run in