nestjs / jwt

JWT utilities module based on the jsonwebtoken package 🔓

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NestJS can't resolve dependencies of the JWT_MODULE_OPTIONS

nmatev opened this issue · comments

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Nest can't resolve dependencies in JWT_MODULE_OPTIONS

Expected behavior

Dependencies are resolved.

Minimal reproduction of the problem with instructions

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 { }

Result

Nest can't resolve dependencies of the JWT_MODULE_OPTIONS (?). Please make sure that the argument at index [0] is available in the JwtModule context. +52ms

Environment


Nest version: 6.3.0
JWT version: 6.0.0 (6.1.1 same problem)
 
For Tooling issues:
- Node version: 10.12.0
- Platform:  Windows 10

Others:

Please, provide a minimal repository which reproduces your issue.

commented

@kamilmysliwiec Having the same issue when using jwt service from submodule using forwardRef. Here is minimal repository with reproducing: https://github.com/AndyGura/nestjs-jwt-issue

commented

Ok, my bad, I forgot to add JwtModule to exports. Now it works like a charm

Please, provide a minimal repository which reproduces your issue.

I have the same problem in new project. In last one the problem was wrong imports in modules. This time I compared all of modules, but can't find what's wrong. Here is link for this project - https://we.tl/t-V79PEWGvje It's really strange what I'm doing wrong to get same error on two difference projects.