【发布时间】:2020-06-26 17:45:21
【问题描述】:
我在我的nestjs 应用程序中使用jwt 令牌,但是当我运行我的项目并使用@UseGuards(AuthGuard()) 装饰器调用控制器时,应用程序调试返回以下错误:
Cannot read property 'challenge' of undefined
【问题讨论】:
我在我的nestjs 应用程序中使用jwt 令牌,但是当我运行我的项目并使用@UseGuards(AuthGuard()) 装饰器调用控制器时,应用程序调试返回以下错误:
Cannot read property 'challenge' of undefined
【问题讨论】:
代替这一行:
@UseGuards(AuthGuard())
使用这个:
@UseGuards(AuthGuard('jwt'))
【讨论】:
您必须将PassportModule 导入为
imports: [
TypeOrmModule.forFeature([UserRepository]),
HttpModule,
ConfigModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
],
进入您要使用默认策略的每个模块。
【讨论】: