Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

Pass parameter to 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;
}
// mixin as a function is imported from @nestjs/common and is a wrapper function that applies the @Injectable() decorator to the class

// Now to use the guard, you need to do something like 
@UseGuards(RoleGuard('admin'))
Comment

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'))
Comment

PREVIOUS NEXT
Code Example
Typescript :: symbol typescript 
Typescript :: json to ts type 
Typescript :: switch in typescript 
Typescript :: python remove accents pandas 
Typescript :: typescript assert non null 
Typescript :: tag for bullets in html 
Typescript :: download blob typescript 
Typescript :: difference in minutes between 2 time inputs laravel 
Typescript :: json in typescript 
Typescript :: ansible facts suse 
Typescript :: generator typescript 
Typescript :: firebase typescript 
Typescript :: linux bash scripts tutorial 
Typescript :: gpluss logi ionic4 
Typescript :: How does a consumer commit offsets in Kafka? it directly commit the offset in Zookeeper it directly send a message to the __consumer_offset it interact with the Group coordinator None 
Typescript :: check if all array elements match closure swift 
Typescript :: typescript narrowing object 
Typescript :: mat dialog position absolute 
Typescript :: how to make a class that inherits from another file class in python 
Typescript :: Simple code example of adding two numbers in typescript 
Typescript :: fputs c++ 
Typescript :: how can you run your test in different environments 
Typescript :: how to print selected elements from a list 
Typescript :: angular library dependencies vs peerdependencies 
Typescript :: Type annotations can only be used in TypeScript files.Vetur(8010) 
Typescript :: how to ignore a field while desiarilizing in java if its type is not wrong 
Typescript :: attend 
Typescript :: how to link to page elements html 
Typescript :: download objects under a prefix in golang 
Typescript :: its getting abort when im trying to open the webcame using opencv 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =