miércoles, 4 de enero de 2023

NestJs Error on SecretKey for JWToken

 Imagine this you are coding happy, configuring your module has auth.module.ts using on your register the classic call to get env values, Classic .env file on you project and get an error like this…

Error: secretOrPrivateKey must have a value

@Module({
imports: [
UserModule,
PassportModule,
JwtModule.register({
secret: process.env.JWT_SECRET,
signOptions: {
expiresIn: process.env.EXPIRES_IN,
audience: process.env.APP_URL,
},
}),
],
controllers: [AuthController],
providers: [AuthService, LocalStrategy, JwtStrategy],
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
imports: [
UserModule,
PassportModule,
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
secret: config.get('JWT_SECRET'),
signOptions: {
expiresIn: config.get('EXPIRES_IN'),
audience: config.get('APP_URL'),
},
}),
})
],
controllers: [AuthController],
providers: [AuthService, LocalStrategy, JwtStrategy],
})

No hay comentarios:

Publicar un comentario

NestJs Error on SecretKey for JWToken

  Imagine this you are coding happy, configuring your module has   auth.module.ts   using on your register the classic call to get env value...