Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support canActivate Guards on routes #25

Open
xmlking opened this issue Jul 13, 2018 · 9 comments
Open

support canActivate Guards on routes #25

xmlking opened this issue Jul 13, 2018 · 9 comments

Comments

@xmlking
Copy link

xmlking commented Jul 13, 2018

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.

@shekohex
Copy link
Member

Hi @xmlking , it seems a good idea, but is there any API Propasol so we can have a clear idea ?

@xmlking
Copy link
Author

xmlking commented Jul 15, 2018

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!

@shekohex
Copy link
Member

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.

@xmlking
Copy link
Author

xmlking commented Jul 15, 2018

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 nestjs/nest#873

@kamilmysliwiec
Copy link

APP_GUARD is a global guard. We should introduce a sort of MODULE_GUARD in this case.

@gkucmierz
Copy link

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.

@gkucmierz
Copy link

APP_GUARD is a global guard. We should introduce a sort of MODULE_GUARD in this case.

Agree

@CatsMiaow
Copy link

CatsMiaow commented Sep 11, 2019

If so (no MODULE_GUARD), is there currently no way to set guard on a per module basis in NestJS?

@cerireyhan
Copy link

Is there any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants