【问题标题】:@nestjs/jwt - Cannot read property 'challenge' of undefined@nestjs/jwt - 无法读取未定义的属性“挑战”
【发布时间】:2020-06-26 17:45:21
【问题描述】:

我在我的nestjs 应用程序中使用jwt 令牌,但是当我运行我的项目并使用@UseGuards(AuthGuard()) 装饰器调用控制器时,应用程序调试返回以下错误:

Cannot read property 'challenge' of undefined

【问题讨论】:

    标签: jwt nestjs


    【解决方案1】:

    代替这一行:

    @UseGuards(AuthGuard())
    

    使用这个:

    @UseGuards(AuthGuard('jwt'))
    

    【讨论】:

      【解决方案2】:

      您必须将PassportModule 导入为

        imports: [
          TypeOrmModule.forFeature([UserRepository]),
          HttpModule,
          ConfigModule,
          PassportModule.register({ defaultStrategy: 'jwt' }),
        ],
      

      进入您要使用默认策略的每个模块。

      【讨论】:

        猜你喜欢
        • 2021-07-29
        • 2021-10-12
        • 2021-01-22
        • 2021-02-27
        • 2021-10-30
        • 2022-12-17
        • 2020-08-19
        • 2021-07-23
        • 2021-05-03
        相关资源
        最近更新 更多