Comments (10)
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.
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.
You should export JwtModule
(add it to the exports
array). There was a bug with dependencies resolution fixed in 6.4.1
from jwt.
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.
providers: [AppService, JwtService],
Remove JwtService
from AppModule
from jwt.
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.
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.
You're right, I had tried multiple options and I mixed code. It works perfectly.
Thanks.
from jwt.
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.
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)
- sign function dosent take secret registred in module HOT 1
- secretOrPrivateKey must have a value HOT 3
- jwt module shoud extends ConfigurableModuleClass HOT 1
- Wrong dependency @types/jsonwebtoken HOT 1
- vulnerability in dependancy jsonwebtoken <=8.5.1 HOT 1
- Updating `jsonwebtoken` dependency HOT 3
- Update `@types/jsonwebtoken` to ^9.0.0 HOT 2
- secretOrPrivateKey must have a value HOT 1
- secretOrPrivateKey has a minimum key size of 2048 bits for RS256 after upgrade to nest/jwt 10.0.2 HOT 1
- How to invalidate a token? HOT 2
- BigInt not supported HOT 1
- type error while using `expiresIn` in `signAsync` HOT 7
- Expose internal Jsonwebtoken errors from @Next/jwt HOT 1
- Issue: Missing 'requestProperty' in @nestjs/jwt Library HOT 1
- JsonWebTokenError: secretOrPublicKey must be an asymmetric key when using RS256 HOT 1
- Error: secretOrPrivateKey must have a value HOT 1
- No valid invalid token for verification HOT 2
- wrong signature for sign() HOT 1
- Unexpected behavior when getting a value from .env file for expiresIn property via the ConfigModule / ConfigService HOT 1
- Can not import JwtService, JwtModule after installed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwt.