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

Can't configure JWT following documentation

Sano123456 opened this issue · comments

commented

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

I am following the documentation present here
https://docs.nestjs.com/techniques/authentication#jwt-functionality
To have faster support I have created a git repository with the problem
https://github.com/Sano123456/nestjs-jwt

First Problem:

in AuthModule if I do as described in documentation and just import UserModule, it return me error of circular dependency between UserModule and AuthModule

@Module({
  imports:[
    UsersModule,
    PassportModule
  ],
  providers: [AuthService],
  controllers: [AuthController],
  exports:[AuthService, LocalStrategy]
})
export class AuthModule {}
 
[ExceptionHandler] Nest cannot create the AuthModule instance.
The module at index [0] of the AuthModule "imports" array is undefined.

Potential causes:
- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
- The module at index [0] is of type "undefined". Check your import statements and the type of the module.

Scope [AppModule -> UsersModule] +6ms

Possibile solution in imports array of AuthModule instead of UserModule put forwardRef(() => UsersModule),
this actually remove the error but not sure if this is the right way

Second problem:

it says that can't find LocalStrategy class even if it's present and declared in AuthModule

[ExceptionHandler] Nest cannot export a provider/module that is not a part of the currently processed module (AuthModule). Please verify whether the exported LocalStrategy is available in this particular context.

Possible Solutions:
- Is LocalStrategy part of the relevant providers/imports within AuthModule?

Possibile solution right now I don't have any solution, I just remove it to understand what is the problem

Third problem problem:

after removing LocalStrategy,

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

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

Expected behavior

to be configured as described

Minimal reproduction of the problem with instructions

https://github.com/Sano123456/nestjs-jwt

What is the motivation / use case for changing the behavior?

Environment



    nest -v -> 7.4.1

 
For Tooling issues:
- Node version:  v10.15.2
- npm version: 6.14.6
- Platform:  any

Others:

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