Open huss-a opened 3 years ago
Pretty sure the "secret" in your constructor and jwtmodule.register need to be "secretOrKey"
@VividLemon this is not correct @nestjs/jwt
does accept the secret
param, the passport-jwt
library on the other side does not and this should be replaced with secretOrKey
.
Im having the same issue. I even try to hardcode the secret string, for discard environment issues. And the result is :
[Nest] 46027 - 05/20/2023, 10:30:27 PM ERROR [ExceptionsHandler] secretOrPrivateKey must have a value Error: secretOrPrivateKey must have a value
I dont know what else do
I believe your .env has to have a SECRET_KEY=""
@neoligero same thing here… I am really struggling and don’t understand why not even hardcoding it I get rid of the ffff error, I m desperate. Did you solve it?
Guys, I also had the error, but I still can't solve it, did you have any success?
Guys, in my case the error was resolved when I imported dotenv directly into main.ts. From what I understand in the Linux environment this needs to be done. the error is not in stategy or guards.
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { ValidationPipe } from '@nestjs/common'
import * as dotenv from 'dotenv'
dotenv.config()
async function bootstrap() {
console.log('JWT_SECRET:', process.env.JWT_SECRET)
const app = await NestFactory.create(AppModule)
app.useGlobalPipes(new ValidationPipe())
await app.listen(3000)
}
bootstrap()
I'm getting a
TypeError: JwtStrategy requires a secret or key
error in a NestJS application, here's the code