0

I am trying to learn NodeJS framework. I have initialized a project for that and now I am trying to add authentication to secure the HTTP access. I follows the NestJS documentation but I have the following error when I inject my UsersService in the AuthService:

[Nest] 14876 - 13/04/2020 à 09:26:19 [ExceptionHandler] Nest can't resolve dependencies of the UsersService (?). Please make sure that the argument UserModel at index [0] is available in the AuthModule context.

Potential solutions:
- If UserModel is a provider, is it part of the current AuthModule?
- If UserModel is exported from a separate @Module, is that module imported within AuthModule?
@Module({
imports: [ /* the Module containing UserModel */ ]
})
+2ms
Error: Nest can't resolve dependencies of the UsersService (?). Please make sure that the argument UserModel at index [0] is available in the AuthModule context.

It seems that it is due to the following injection in my UsersService :

constructor(@InjectModel('User') private readonly UserModel: Model) {}

but I doesn't know how to solve this problem. My training project is stored on github :

https://github.com/afontange/nest-js.git

I read other tickets on same subject but I don't know what is the solution for my problem.

Thanks for your help.

2 Answers 2

0
export const UsersSchema = new Schema({
  name: String,
});


Module({
   imports: [
   MongooseModule.forFeature([{ name: 'Users', schema: UsersSchema }]) // add
  ],
  controllers: [],
  providers: [],
  exports: []

}) export class AuthModule {}

Do you add in your Auth.module.ts

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for all the answers but I received on github the following comment : Remediation Upgrade minimist to version 0.2.1 or later. For example: "dependencies": { "minimist": ">=0.2.1" } or… "devDependencies": { "minimist": ">=0.2.1" } I have upgraded minimist library and all seems OK now. I don't understant why this librairy is not installed by default by NestJS installer when you create a new project.
0

The AuthModule is the following:

import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { UsersModule } from '../users/users.module';
import { PassportModule } from '@nestjs/passport';
import { LocalStrategy } from './local.strategy';
import { UsersService } from '../users/users.service';

@Module({
  imports: [UsersModule, PassportModule],
  providers: [AuthService, LocalStrategy, UsersService],
})
export class AuthModule {}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.