我使用NestJS jwt passport对用户进行身份验证。我遵循文档,这是我的应用程序模块:
import { Module } from '@nestjs/common';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from './auth/auth.module';
import { ConfigModule } from '@nestjs/config';
import configuration from '../config/configuration';
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
TypeOrmModule.forRoot(),
UserModule,
AuthModule,
],
})
export class AppModule {}
下面是我的auth模块:
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { PassportModule } from '@nestjs/passport';
import { UserModule } from '../user/user.module';
import { LocalStrategy } from './local.strategy';
import { JwtStrategy } from './jwt.strategy';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { AuthController } from './auth.controller';
@Module({
imports: [
UserModule,
PassportModule,
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
secret: configService.get('jwt.secret'),
signOptions: {
expiresIn: configService.get('jwt.expiresIn'),
},
}),
inject: [ConfigService],
}),
],
providers: [AuthService, LocalStrategy, JwtStrategy],
exports: [AuthService],
controllers: [AuthController],
})
export class AuthModule {}
每次运行npm run start
时,我都会收到以下错误消息:
Nest can't resolve dependencies of the JWT_MODULE_OPTIONS (?). Please make sure that the argument ConfigService at index [0] is available in the JwtModule context.
我已经搜索了这个问题,但仍然不能解决这个问题。有人能帮我吗?谢谢。
发布于 2020-02-18 17:16:25
正如其他人提到的,一种选择是使用isGlobal: true
设置使ConfigModule
成为全局的。否则,在@nestjs/config@0.2.3
中使用should be fixed,现在应该可以像文档显示的那样工作。
发布于 2020-02-18 11:54:24
我与这个问题斗争了几个小时,但据Chau Tran说,在用ConfigModule.forRoot({ isGlobal: true })
使ConfigModule
全球化后,我所有的问题都解决了。?
https://stackoverflow.com/questions/60255641
复制相似问题