【发布时间】:2019-12-19 04:06:15
【问题描述】:
我编译失败,出现这个错误:
Nest 无法解析 JWT_MODULE_OPTIONS (?) 的依赖关系。请确保索引 [0] 处的参数在 JwtModule 上下文中可用。 +52 毫秒
我看到了与模块和服务类似的依赖问题,但它们对我不起作用。在我的 auth.module.ts 中使用 JwtModule:
import { JwtModule } from '@nestjs/jwt';
@Module({
imports: [
TypeOrmModule.forFeature([User, Role]),
ConfigModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.registerAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
secretOrPrivateKey: config.jwtSecret,
type: configService.dbType as any,
host: configService.dbHost,
port: configService.dbPort,
username: configService.dbUsername,
password: configService.dbPassword,
database: configService.dbName,
entities: ['./src/data/entities/*.ts'],
signOptions: {
expiresIn: config.expiresIn,
},
}),
}),
],
providers: [AuthService, JwtStrategy],
controllers: [AuthController],
})
export class AuthModule { }
我不知道如何修复这个错误...使用 jwt 6.1.1
编辑:在我之前的项目中使用 jwt 6.0.0,所以我降级了它,但问题没有解决。
【问题讨论】:
-
真正快速的问题:为什么要将数据库选项传递给 JWT 模块?
标签: typescript module nestjs