-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"TypeError: JwtStrategy requires a secret or key" with NestJS #227
Comments
Pretty sure the "secret" in your constructor and jwtmodule.register need to be "secretOrKey" |
@VividLemon this is not correct |
Im having the same issue. I even try to hardcode the secret string, for discard environment issues. [Nest] 46027 - 05/20/2023, 10:30:27 PM ERROR [ExceptionsHandler] 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() |
@Caique-LF Yeah, you're right, I solved the issue following what you say. Thanks |
In my case, I was using @nestjs/config and solved the isuue by indicating the file path of .env file when registering the ConfigModule as follows: ConfigModule.forRoot({isGlobal: true, envFilePath: 'C:/Users/me/Desktop/project/backend/src/.env'}) You can also use the relative path instead of the long one I have provided. |
I'm getting a
TypeError: JwtStrategy requires a secret or key
error in a NestJS application, here's the codeThe text was updated successfully, but these errors were encountered: