简体   繁体   English

NestJS authGuard 有效

[英]NestJS authGuard dosent works

I'm implementing @nestjs/passport ('jwt') and using (exactly like in the instructions) the @UseGuards(AuthGuard()) decorator but i'm getting the following exception:我正在实现@nestjs/passport ('jwt') 并使用(与说明完全一样) @UseGuards(AuthGuard())装饰器,但出现以下异常:

common_1.Optional is not a function common_1.Optional 不是函数

Does anyone have any idea what could be the problem?有谁知道可能是什么问题?

Dependencies:依赖项:

"@nestjs/common": "^5.0.0", "@nestjs/common": "^5.0.0",

 "@nestjs/core": "^5.0.0", "@nestjs/cqrs": "^5.1.1", "@nestjs/jwt": "^0.2.0", "@nestjs/mongoose": "^5.1.0", "@nestjs/passport": "^5.1.0", "@nestjs/swagger": "^2.4.4", "@nestjs/typeorm": "^5.2.2", "automapper-ts": "^1.9.0", "config": "^2.0.1", "fastify-formbody": "^2.0.0", "lodash": "^4.17.10", "mongodb": "^3.1.6", "mongoose": "^5.2.9", "mysql": "^2.16.0", "nestjs-rmq": "^0.1.3", "nestjs-typegoose": "^5.0.1", "passport": "^0.4.0", "passport-jwt": "^4.0.0", "reflect-metadata": "^0.1.12", "rxjs": "^6.0.0", "typegoose": "^5.4.0", "typeorm": "^0.2.7", "typescript": "^2.6.2",

The dependencies are out of date.依赖项已过时。 Try running npm update .尝试运行npm update

Perhaps I badly understand the question, but to use a guard, you can give a guard instance or give the class and let nest create the instance, a guard is **not a function*也许我不太理解这个问题,但是要使用守卫,您可以提供守卫实例或提供类并让嵌套创建实例,守卫是**不是函数*

@UseGuards(AuthGuard()) should be : @UseGuards(new AuthGuard()) or @UseGuards(AuthGuard) @UseGuards(AuthGuard())应该是: @UseGuards(new AuthGuard())@UseGuards(AuthGuard)

It looks like you use old dependencies.看起来您使用旧的依赖项。

install npm g npm-check安装 npm g npm-check

RUN npm-check -u运行 npm-check -u

https://www.npmjs.com/package/npm-check https://www.npmjs.com/package/npm-check

dependencies problem依赖问题

try this :尝试这个 :

$ sudo npm install -g npm-check $ sudo npm install -g npm-check

$ npm-check -u $ npm-check -u

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM