Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument at index [0] is available in the AuthModule context.
See original GitHub issueI’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
I get :
Error: Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument at index [0] is available in the AuthModule context.
Expected behavior
The app should run and the AuthService dependancies can be injected in AuthModule
Minimal reproduction of the problem with instructions
app.module.ts
@Module({
imports: [
TypeOrmModule.forRoot(),
UserModule,
AuthModule
],
controllers: [AppController, UserController],
providers: [AppService, UserService],
})
export class AppModule {
constructor(private readonly connection: Connection) {
}
}
auth.module.ts :
@Module({
imports: [UserModule],
providers: [AuthService, HttpStrategy]
})
export class AuthModule {
}
http.strategy.ts :
@Injectable()
export class HttpStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super();
}
async validate(token: string) {
const user = await this.authService.validateUser(token);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}
auth.service.ts :
@Injectable()
export class AuthService {
constructor(private readonly userService: UserService) {}
async validateUser(token: string): Promise<any> {
// Validate if token passed along with HTTP request
// is associated with any registered account in the database
return await this.userService.findOneByToken(token);
}
}
What is the motivation / use case for changing the behavior?
I want to add an Authentication system in my app.
Environment
Nest version: 5.4.0
For Tooling issues:
- Node version: 10.15.0
- Platform: Windows
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
nestjs - Nest can't resolve dependencies of the AuthService ...
Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument at index [0] is available in the AuthModule context....
Read more >Nest can't resolve dependencies of the UsersService ... - Reddit
Please make sure that the argument PrismaService at index [0] is available in the UsersService context. I've read about 30 different S.O./reddit ...
Read more >Common errors - FAQ - A progressive Node.js framework
Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument <unknown_token> at index [<index>] is available in the <module> ......
Read more >please make sure that the argument databaseconnection at ...
bash Error: Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument at index [0] is available in the...
Read more >Authentication in a Nest.js Application with Neo4j - Medium
Please make sure that the argument UserService at index [0] is available in the AuthModule context.Potential solutions: - If UserService is a ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, i think you are missing the export of the provider (you are trying to use the service in a different module) I have ran into the same issue before
My issues is solved ! The solution is : auth.module.ts :
Just add the UserService in provider.