Skip to content

support canActivate Guards on routes  #25

@xmlking

Description

@xmlking

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.

Activity

shekohex

shekohex commented on Jul 13, 2018

@shekohex
Member

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

xmlking

xmlking commented on Jul 15, 2018

@xmlking
Author

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

shekohex commented on Jul 15, 2018

@shekohex
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

xmlking commented on Jul 15, 2018

@xmlking
Author

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

kamilmysliwiec commented on Mar 8, 2019

@kamilmysliwiec

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

gkucmierz

gkucmierz commented on May 13, 2019

@gkucmierz

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

gkucmierz commented on May 13, 2019

@gkucmierz

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

Agree

CatsMiaow

CatsMiaow commented on Sep 11, 2019

@CatsMiaow

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

cerireyhan

cerireyhan commented on May 18, 2020

@cerireyhan

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xmlking@gkucmierz@CatsMiaow@cerireyhan@shekohex

        Issue actions

          support canActivate Guards on routes · Issue #25 · nestjsx/nest-router