Authentication Passport strategy如何在nestJS中选择正确的jwt策略?

Authentication Passport strategy如何在nestJS中选择正确的jwt策略?,authentication,jwt,passport.js,nestjs,passport-jwt,Authentication,Jwt,Passport.js,Nestjs,Passport Jwt,我在nestJS中使用passport实现jwt时遵循了这一点,一切都按预期进行,但我对这种方法有一个澄清,如果我们使用UseGuards(@authGuards()),应用程序知道使用passportstrategy来验证令牌,并调用validate方法进一步进行验证,但是为什么passport strategy知道为调用validate方法选择正确的jwt strategy类,没有明确提到我们要求passport strategy使用jwtStrategy类,并且它不是默认导出,但是验证令牌

我在nestJS中使用passport实现jwt时遵循了这一点,一切都按预期进行,但我对这种方法有一个澄清,如果我们使用UseGuards(@authGuards()),应用程序知道使用passportstrategy来验证令牌,并调用validate方法进一步进行验证,但是为什么passport strategy知道为调用validate方法选择正确的jwt strategy类,没有明确提到我们要求passport strategy使用jwtStrategy类,并且它不是默认导出,但是验证令牌后passportstrategy如何调用正确的JwtStrategy类来验证方法呢?

答案的关键在于以下代码块:(摘自链接文章)

@模块({
进口:[……]。。。,
PassportModule.register({
defaultStrategy:'jwt',
属性:“用户”,
会话:错误,
}),    ...  
],  
控制器:[AuthController],
提供者:[AuthService,JwtStrategy],
导出:[PassportModule],
})
导出类AuthModule{}
defaultStrategy
告诉Nest“当我使用
AuthGuard()
时,将此策略作为要使用的策略”。在本例中,
'jwt'
。每个passport策略都有一个默认的passport名称,以了解正在使用的策略。在
passport jwt
的情况下,当我们扩展passport本地策略时,我们正在使用@nestjs/passport自动为我们配置的AuthGuard