Nest can't resolve dependencies of the JwtService (?). Please make sure that the argument JWT_MODULE_OPTIONS at index [0] is available in the JwtModule context.
massivefermion opened this issue · 1 comments
massivefermion commented
I'm receiving the error in the title and nothing I got from searching the internet helped.
These are the relevant parts of my code:
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ForbiddenException } from '@nestjs/common';
@Injectable()
export class TokenService {
constructor(private readonly jwt: JwtService) {}
async sign(payload: object) {
return this.jwt.sign({ payload });
}
async verify(token: string) {
try {
const { payload } = this.jwt.verify(token);
return payload;
} catch (exc) {
throw new ForbiddenException();
}
}
}
import { Module } from '@nestjs/common'
import { TokenService } from './token.service'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { JwtModule } from '@nestjs/jwt'
@Module({
providers: [TokenService],
imports: [
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
secret: config.get<string>('SECRET'),
}),
}),
],
exports: [TokenService],
})
export class TokenModule {}
import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { TokenModule } from './token/token.module'
import { AuthModule } from './auth/auth.module'
import { ProfileModule } from './profile/profile.module'
import { MongooseModule } from '@nestjs/mongoose'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { JwtModule } from '@nestjs/jwt'
@Module({
imports: [
MongooseModule.forRoot('mongodb://localhost/db-name'),
ConfigModule.forRoot(),
JwtModule,
TokenModule,
AuthModule,
ProfileModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
kamilmysliwiec commented
Please search through some of our old issues on this (this has been discussed several times in the past).