I was following along with the jwt example like found here https://docs.nestjs.com/techniques/authentication. I copied and pasted the example. After npm installing the necessary bits and bops I got this error which does not occur in the sample which I just copied. Of which I have no idea what it means! Anyone any ideas?
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)
The project lacks @types/passport-jwt
typings, so they should be additionally installed:
npm i -D @types/passport-jwt
This results in
src\auth\jwt.strategy.ts (10,6): Call target does not contain any signatures. (2346)
error, because @nestjs/passport
wasn't properly typed; PassportStrategy
return type is any
.
In order to fix this,
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
...
should be changed to:
import { ExtractJwt, Strategy } from 'passport-jwt';
import { AbstractStrategy, PassportStrategy } from '@nestjs/passport';
...
const PassportJwtStrategy: new(...args) => AbstractStrategy & Strategy = PassportStrategy(Strategy);
@Injectable()
export class JwtStrategy extends PassportJwtStrategy {
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With