Swagger: @UseGuards(AuthGuard('jwt')) stopped working after update to latest modules

Created on 25 Jan 2020  路  13Comments  路  Source: nestjs/swagger

Regression

@UseGuards(AuthGuard('jwt')) stopped working after update to latest modules

Potential Commit/PR that introduced the regression**

Describe the regression

After updating to latest NestJS module using nest u, running npm run start leads to error in /node_modules/reflect-metadata/Reflect.js:354

> nest start

/<project_folder>/node_modules/reflect-metadata/Reflect.js:354
                throw new TypeError();
                ^

TypeError
    at Object.getMetadata (/<project_folder>/node_modules/reflect-metadata/Reflect.js:354:23)
    at Object.extendArrayMetadata (/<project_folder>/node_modules/@nestjs/common/utils/extend-metadata.util.js:4:35)
    at UseGuards (/<project_folder>/node_modules/@nestjs/common/decorators/core/use-guards.decorator.js:35:36)
    at DecorateProperty (/<project_folder>/node_modules/reflect-metadata/Reflect.js:553:33)
    at Object.decorate (/<project_folder>/node_modules/reflect-metadata/Reflect.js:123:24)
    at __decorate (/<project_folder>/dist/src/app.controller.js:4:92)
    at Object.<anonymous> (//<project_folder>/dist/src/app.controller.js:46:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)

Input Code

  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  @Get('test')
  getHelloTest(@CurrentUser() currentUser: CurrentUserInterface): string {
    return this.appService.getHello(currentUser.user);
  }

Expected behavior/code

Calling npm run start will run smoothly without errors.

Environment

PRIOR TO UPDATE (WORKING NO RUN ERRORS)


[System Information]
OS Version     : macOS Catalina
NodeJS Version : v10.18.1
NPM Version    : 6.13.4 

[Nest CLI]
Nest CLI Version : 6.14.0 (global)
Nest CLI Version: 

[Nest Platform Information]
platform-express version : 6.10.14
platform-fastify version : 6.10.14
passport version         : 6.1.1
swagger version          : 4.1.15
typeorm version          : 6.2.0
common version           : 6.10.14
core version             : 6.10.14
jwt version              : 6.1.1

Outdated Package           Current  Wanted  Latest  Location
@nestjs/cli                6.14.0  6.14.1  6.14.1  api-v2
@nestjs/common            6.10.14  6.11.1  6.11.1  api-v2
@nestjs/core              6.10.14  6.11.1  6.11.1  api-v2
@nestjs/platform-express  6.10.14  6.11.1  6.11.1  api-v2
@nestjs/platform-fastify  6.10.14  6.11.1  6.11.1  api-v2
@nestjs/swagger            4.1.15   4.2.0   4.2.0  api-v2
@nestjs/testing           6.10.14  6.11.1  6.11.1  api-v2
@types/hapi__joi           16.0.7  16.0.8  16.0.8  api-v2
@types/jest                24.9.0  24.9.1  24.9.1  api-v2
@types/node                13.1.8  13.5.0  13.5.0  api-v2
mysql                      2.18.0  2.18.1  2.18.1  api-v2
ts-jest                    24.3.0  24.3.0  25.0.0  api-v2

AFTER UPDATE VIA nest u


[System Information]
OS Version     : macOS Catalina
NodeJS Version : v10.18.1
NPM Version    : 6.13.4 

[Nest CLI]
Nest CLI Version : 6.14.0 

[Nest Platform Information]
platform-express version : 6.11.1
platform-fastify version : 6.11.1
passport version         : 6.1.1
swagger version          : 4.2.0
typeorm version          : 6.2.0
common version           : 6.11.1
core version             : 6.11.1
jwt version              : 6.1.1

Outdated Package       Current  Wanted  Latest  Location
@nestjs/cli        6.14.0  6.14.1  6.14.1  api-v2
@nestjs/testing   6.10.14  6.11.1  6.11.1  api-v2
@types/hapi__joi   16.0.7  16.0.8  16.0.8 api-v2
@types/jest        24.9.0  24.9.1  24.9.1  api-v2
@types/node        13.1.8  13.5.0  13.5.0  api-v2
mysql              2.18.0  2.18.1  2.18.1  api-v2
ts-jest            24.3.0  24.3.0  25.0.0  api-v2

Most helpful comment

Fixed in 4.2.2 (@nestjs/swagger)

All 13 comments

Please, provide a minimal repository which reproduces your issue.

@kamilmysliwiec i'll try to copy the project we are working to another repo and make it as minimal as possible

@kamilmysliwiec i've uploaded a minimal repo to recreate the issue

Below is the master branch (current running version - no issue running npm run start)
https://github.com/AcidSlide/nestjs-regression-test
image

Below is after running nest update and running npm run build && npm run start
https://github.com/AcidSlide/nestjs-regression-test/tree/test-update-regression
image

The same issue after updating to the latest version.

@aprisniak just curious, what OS are you using and what Node version?

@aprisniak just curious, what OS are you using and what Node version?

Node v12.14.1
yarn v1.21.1
MacOS 10.15.2

@aprisniak just curious, what OS are you using and what Node version?

Node v12.14.1
yarn v1.21.1
MacOS 10.15.2

Thanks @aprisniak so the regression has nothing to do with Node version

Also experiencing this with latest version on every guard that I have.

This is caused by @ApiBearerAuth. Let me move this issue

Fixed in 4.2.2 (@nestjs/swagger)

confirming latest nest modules (including @nestjs/swagger) is working with our project, no issues encountered so far on base test.

We will know once we have done a full regression test on our project.

Thanks @kamilmysliwiec

@kamilmysliwiec Tks a lot! Now it is working again.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fiorello picture Fiorello  路  5Comments

cdiaz picture cdiaz  路  4Comments

ivashog picture ivashog  路  3Comments

vh13294 picture vh13294  路  4Comments

dennisameling picture dennisameling  路  4Comments