Using

Using for routers

import{RBAcPermissions,RBAcGuard}from'nestjs-rbac';@Controller()exportclassRbacTestController{@RBAcPermissions('permission','permission@create')@UseGuards(AuthGuard,// need for using user into the requestRBAcGuard,)@Get('/')asynctest1():Promise<boolean>{returntrue;}}

Using the custom filters

filter is a great opportunity of customising behaviour RBAC.
For creating filter, there is need to implement IFilterPermission interface, which requires for implementing can method, and bind a key filter with filter implementation, like below:

Also RBAC has a default filter RBAC_REQUEST_FILTER which has request object as argument:

Example:

//===================== filterexportclassRequestFilterimplementsIFilterPermission{can(params?:any[]):boolean{returnparams[0].headers['test-header']==='test';}}//===================== storageexportconstRBAC:IStorageRbac={roles:['role'],permissions:{permission1:['filter1','filter2',RBAC_REQUEST_FILTER],},grants:{role:[`permission1@${RBAC_REQUEST_FILTER}`],},filters:{[RBAC_REQUEST_FILTER]:RequestFilter,},};//===================== using for routes@RBAcPermissions(`permission1@${RBAC_REQUEST_FILTER}`)@UseGuards(AuthGuard,RBAcGuard,)@Get('/')asynctest4():Promise<boolean>{returntrue;}