Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

Pass a parameter to a nestjs guard?

export const RoleGuard = (role: string) => {
  class RoleGuardMixin implements CanActivate {
    canActivate(context: ExecutionContext) {
      // do something with context and role
      return true;
    }
  }

  const guard = mixin(RoleGuardMixin);
  return guard;
}

// Now to use the guard, you need to do something like 

@UseGuards(RoleGuard('admin'))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Pass #parameter #nestjs
ADD COMMENT
Topic
Name
3+7 =