I'm trying to use the JwtService from nestjs to decode an access_token in a controller, but I don't know how to inject this service in the constructor.
Here is my code:
import { JwtService } from '@nestjs/jwt';
import { Controller, Get, Post, Body, Req } from '@nestjs/common';
@Controller('event')
export class EventController {
constructor(
private readonly jwtService: JwtService) {}
@Get('/questions')
async getQuestionsAsync(): Promise<Question[]> {
const decodedToken = this.jwtService.decode(accessToken);
...
}
I'm getting this error:
Error: Nest can't resolve dependencies of the EventController (EventService, ?). Please make sure that the argument JwtService at index [1] is available in the EventModule context.
I have already tried to add @Inject(JwtService) as an attribute to the private variable, but the error is the same.
So, how do I correctly inject the JwtService in the controller ?