JwtStrategy requires a secret or key
aabanaag opened this issue · 12 comments
I get this error JwtStrategy requires a secret or key I followed the steps from NestJS on how to integrate passport for authentication.
constructor(private readonly authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET
})
console.log(process.env.JWT_SECRET)
console.log(this)
}
the console looks like this
JwtStrategy {
name: 'jwt',
_secretOrKeyProvider: [Function],
_verify: [Function],
_jwtFromRequest: [Function],
_passReqToCallback: undefined,
_verifOpts: {
audience: undefined,
issuer: undefined,
algorithms: undefined,
ignoreExpiration: false
},
authService: AuthService {
repository: Repository {
manager: [EntityManager],
metadata: [EntityMetadata],
queryRunner: undefined
},
userService: UserService { repository: [Repository] }
}
}
The full error:
[Nest] 3713 - 05/11/2020, 2:42:42 PM [ExceptionHandler] JwtStrategy requires a secret or key +14ms
TypeError: JwtStrategy requires a secret or key
at new JwtStrategy (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/passport-jwt/lib/strategy.js:45:15)
at new MixinStrategy (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:31:13)
at new LocalStrategy (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/dist/src/auth/local.strategy.js:18:9)
at Injector.instantiateClass (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/@nestjs/core/injector/injector.js:289:19)
at callback (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/@nestjs/core/injector/injector.js:76:41)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Injector.resolveConstructorParams (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/@nestjs/core/injector/injector.js:117:24)
at async Injector.loadInstance (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/@nestjs/core/injector/injector.js:80:9)
at async Injector.loadProvider (/Users/jongbanaag/Documents/code/sideline/hyperspotters-api/node_modules/@nestjs/core/injector/injector.js:37:9)
at async Promise.all (index 4)
✨ Done in 11.06s.
Any ideas?
Figured out the issue, on my local.strategy file instead of importing Strategy from passport-local it imported from passport-jwt which is causing the issue
What did you do to fix this? I am having same issue too and I can't seem to pin point what needs to be fixed
Check "local.strategy.ts" if you have one and replace
import { Strategy } from 'passport-jwt'; with import { Strategy } from 'passport-local';
Resolví el problema, en mi archivo local.strategy en lugar de importar la estrategia de passport-local que importó de passport-jwt que está causando el problema
this worked for me
Figured out the issue, on my local.strategy file instead of importing Strategy from passport-local it imported from passport-jwt which is causing the issue
this worked for me, excellent!
It worked for me as well. But I would like to know why is it this way? If anyone can explain would really help, since the entire reason for importing from passport-jwt
is that we want to implement that particular strategy
thank you for that passport-local
gooood
thanks
Figured out the issue, on my local.strategy file instead of importing Strategy from passport-local it imported from passport-jwt which is causing the issue
thanks you help me alot
Figured out the issue, on my local.strategy file instead of importing Strategy from passport-local it imported from passport-jwt which is causing the issue
Thank you !!! I could use your idea to solve my similar problem
Figured out the issue, on my local.strategy file instead of importing Strategy from passport-local it imported from passport-jwt which is causing the issue
thanks so much, this helped me
thanks boss