【发布时间】:2018-11-12 06:31:21
【问题描述】:
我一直在关注 jwt 示例,就像在此处找到的 https://docs.nestjs.com/techniques/authentication 一样。我复制并粘贴了示例。在 npm 安装必要的位和 bops 后,我得到了这个错误,这在我刚刚复制的示例中没有发生。我不知道这意味着什么!有人有什么想法吗?
TypeError: Class constructor MixinStrategy cannot be invoked without 'new'
8 | export class JwtStrategy extends PassportStrategy(Strategy) {
9 | constructor(private readonly authService: AuthService) {
> 10 | super({
11 | jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
12 | secretOrKey: 'secretKey',
13 | });
at new JwtStrategy (data/auth/strategies/jwt.strategy.ts:10:5)
at resolveConstructorParams (../node_modules/@nestjs/core/injector/injector.js:64:84)
at Injector.resolveConstructorParams (../node_modules/@nestjs/core/injector/injector.js:86:30)
【问题讨论】:
-
你能提供一种复制问题的方法——回购等吗?可能特定于包版本或其他。
-
当然,克隆这个文件夹github.com/nestjs/nest/tree/master/sample/19-auth npm i && npm start 它会在 Windows 10 和节点 8.11.2 上显示出来
-
我无法复制您遇到的错误。 MixinStrategy 没有问题。您当前的代码可能与您链接的代码不同。但是我在打字方面遇到了问题。我建议在github.com/nestjs/nest 和github.com/nestjs/passport 中针对不正确的 PassportStrategy 类型打开有关此示例的问题(19-auth 未命中 @types/passport-jwt 依赖项)。无论如何,我无法使这个示例可行。服务器运行但以 404 响应。
-
不确定此时是否可以做任何事情。我曾认真考虑将 NestJS 作为我的下一个框架,但它似乎还不够成熟。文档有些缺乏,开箱即用的示例并没有真正的帮助。感谢您向 SO 提出这个问题,这令人大开眼界。
-
检查您的 tsconfig.json 以确保“目标”是“es6”
标签: typescript jwt passport.js nestjs