nest-router
nest-router copied to clipboard
support canActivate Guards on routes
It is kind of hard to defined Guards (e.g., AuthGuard) at global level but exclude at specific route with standard @nestjs.
it would be nice if this package provide a way to define canActivate
with route definition so that we can have some control over customizing enforcing guards declaratively.
Hi @xmlking , it seems a good idea, but is there any API Propasol so we can have a clear idea ?
Thinking something like this.
const routes: Routes = [
{
path: '/api',
canActivate: [AuthGuard] ,
children: [
{
path: '/cats',
module: CatsModule,
canActivate: [CatGuard]
},
{
path: '/dogs',
module: DogsModule,
canActivate: [DogGuard]
},
],
},
];
The question for discussion:
if there are more then one effective Guards on a route, how we can compose and apply guards to that route? should we apply and
condition or should we react based on previous guard's result!
Hmm, i'm thinking since Guards
are injectable, and we can add it directly to providers: []
Nest Router actually have access to that providers
array, we can just push it there with APP_GUARD
token.
In my opinion it just a helper or a method sugar for applying guards to modules.
Agree, most of us adding guards via APP_GUARD and activating via decorators. My concern was in general how nestjs handle multiple global guards as I am asking for clarification here https://github.com/nestjs/nest/issues/873
APP_GUARD
is a global guard. We should introduce a sort of MODULE_GUARD
in this case.
Hi @xmlking , it seems a good idea, but is there any API Propasol so we can have a clear idea ?
I think this can be done similar like its done in angular.
APP_GUARD
is a global guard. We should introduce a sort ofMODULE_GUARD
in this case.
Agree
If so (no MODULE_GUARD
), is there currently no way to set guard on a per module basis in NestJS?
Is there any updates on this issue?