Giter Site home page Giter Site logo

Comments (10)

cheelahim avatar cheelahim commented on May 3, 2024

Hi @vnenkpet. Not sure when this issue was introduced but I'm getting the same error having the following versions installed:

    "@nestjs/common": "^6.4.1",
    "@nestjs/core": "^6.4.1",
    "@nestjs/jwt": "^6.1.1",

Did you find the solution already? If not, try to re-export JwtModule from your AuthModule (in the same way you do it for PassportModule) to expose JwtService for ServerModule.

from jwt.

manueltg89 avatar manueltg89 commented on May 3, 2024

Same problem after upgrade to NestJS 6. I've installed new project with NestJS 6 and If I put JwtModule in separate AuthModule and after I import in other module I get same problem.

from jwt.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024

You should export JwtModule (add it to the exports array). There was a bug with dependencies resolution fixed in 6.4.1

from jwt.

manueltg89 avatar manueltg89 commented on May 3, 2024

I had tried that previously but same problem,

Error: Nest can't resolve dependencies of the JwtService (?). Please make sure that the argument at index [0] is available in the AuthModule context.

App module:

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth.module';
import { JwtService } from '@nestjs/jwt';
@Module({
  imports: [AuthModule],
  controllers: [AppController],
  providers: [AppService, JwtService],
})
export class AppModule {}

Auth module:

import { JwtModule, JwtService } from '@nestjs/jwt';
import { Module } from '@nestjs/common';

@Module({
    imports: [JwtModule.register({ secret: 'hard!to-guess_secret' })],
    providers: [JwtService],
    exports: [JwtModule]
})
export class AuthModule {}

Thanks.

from jwt.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024
providers: [AppService, JwtService],

Remove JwtService from AppModule

from jwt.

manueltg89 avatar manueltg89 commented on May 3, 2024

Not working, same fail :

I update files:

App module:

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth.module';

@Module({
  imports: [AuthModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Auth module:

import { JwtModule, JwtService } from '@nestjs/jwt';
import { Module } from '@nestjs/common';

@Module({
    imports: [JwtModule.register({ secret: 'hard!to-guess_secret' })],
    providers: [JwtService],
    exports: [JwtModule]
})
export class AuthModule {}

Thanks.

from jwt.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024

Why do you have JwtService in providers array in AuthModule? It's not how it is supposed to work.
See more here https://docs.nestjs.com/modules

Remove providers: [JwtService] as well

from jwt.

manueltg89 avatar manueltg89 commented on May 3, 2024

You're right, I had tried multiple options and I mixed code. It works perfectly.

Thanks.

from jwt.

RobinLebhar avatar RobinLebhar commented on May 3, 2024

HI guys I still have the problem even with your suggestions :/

App.module :

@Module({
  imports: [
    MongooseModule.forRoot(process.env.MONGODB_URI,
      { ...mongooseConfig }
    ),
    UserModule,
    AuthModule,
  ],
})

auth.module

@Module({
  imports: [
    UserModule,
    PassportModule,
    MongooseModule.forFeature([
      { name: emailVerificationSchemaName, schema: EmailVerificationSchema },
      { name: userSchemaName, schema: UserSchema }
    ]),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register({
      secret: process.env.SECRET_JWT,
      signOptions: { expiresIn: '60s' },
    }),

  ],
  controllers: [AuthController],
  providers: [AuthService, JwtStrategy],
  exports: [AuthService]

})

User.module :

@Module({
    imports: [
        MongooseModule.forFeature([
            { name: emailVerificationSchemaName, schema: EmailVerificationSchema },
            { name: userSchemaName, schema: UserSchema }
        ]),
    ],
    controllers: [UserController],
    providers: [AuthService, UserService],
    exports: [UserService]

})

Everything works fine but as soon as I write private readonly jwtService: JwtService in my auth.service I got the following error and the app crashes :

Nest can't resolve dependencies of the AuthService ([object Object], EmailVerificationModel, ?). Please make sure that the argument at index [2] is available in the UserModule context.

Also I find it weird it says "in the UserModule context"

Also here is the contractor of auth.service

 constructor(
    @Inject(forwardRef(() => UserService))
    private readonly userService: UserService,
    @InjectModel(emailVerificationSchemaName) private readonly emailVerificationDocument: Model<EmailVerificationDocument>,
    private readonly jwtService: JwtService // this line generate the error, if I remove it the app works fine
  ) { }

Any idea guys ? Thanks !

from jwt.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

from jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.