访问增强版ExecutionContext(阅读更多内容)为警卫提供了更多的超级大国,所有这些都建立在简化的API之上。
第一个是ExecutionContext实例(与看守器完全相同的对象)。ExecutionContext继承自ArgumentsHost(之前在“异常过滤器”一章中看到过)。
asyncupvotePost(@Args('postId')postId:number){returnawaitthis.postsService.upvoteById({id:postId});} 执行上下文 但是,ExecutionContext
另一方面,Guards可以访问ExecutionContext实例,因此确切知道下一步将要执行什么。
import{ExecutionContext,Injectable,UnauthorizedException,}from'@nestjs/common';import{AuthGuard}from'
@Injectable()classHttpCacheInterceptorextendsCacheInterceptor{trackBy(context:ExecutionContext):string