When configuring my application, I have implemented global filters using the code snippet below.
const server = await NestFactory.create(ApplicationModule);
server.useGlobalGuards(new (AuthGuard('jwt')));
The structure of my ApplicationModule is outlined as follows.
import { Module } from '@nestjs/common';
import { JwtModule, JwtModuleOptions } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { Strategy } from 'passport-jwt';
import { AppController } from './application.controller';
import { ConfigModule, ConfigType } from '@nestjs/config';
import jwtConfig from './config/jwt.config';
@Module({
imports: [
ConfigModule.forFeature(jwtConfig),
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.registerAsync({
imports: [ConfigModule.forFeature(jwtConfig)],
useFactory: (config: ConfigType<typeof jwtConfig>) => {
return {
secret: config.secretKey,
signOptions: { expiresIn: config.expiresIn },
} as JwtModuleOptions;
},
inject: [jwtConfig.KEY],
}),
],
controllers: [
AppController
],
providers: [Strategy],
})
export class ApplicationModule {}
However, I encountered the following error during execution:
TypeError: Cannot read property 'secretOrKeyProvider' of undefined
I am unsure of what may be causing this issue. I have yet to come across any examples utilizing Global auth guards in a similar manner. Any insights or guidance would be greatly appreciated.