Your .env
file is not yet read in when your JwtModule
is instantiated. So either read it in earlier e.g. in your main.ts
before the nest app is created or better: create a ConfigService
and make the dependency on your config explicit:
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
secret: configService.jwtSecret,
}),
inject: [ConfigService],
}),
See this answer on how to create a ConfigService
.