canActivate(context: ExecutionContext): boolean {
const request = context.switchToHttp().getRequest();
const params = request.params;
const id = params.id; // automatically parsed
}
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'))