Search code examples
nestjs

Nest can't resolve dependencies of the RolesGuard. Please make sure that the argument Reflector at index [1] is available in the PhotoModule context


When I use rolesGuard before any handler Reflector error coming up. Please support me to deal with this thing.

Here, i am using rolesGuard.

import {
Controller,
Post,
Body,
UseGuards,
} from '@nestjs/common';
import { PhotoService } from './photo.service';

import { CreatePhotoDto } from './dto/create-photo.dto';
import { Photo } from './models/photo.model';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { PhotoLikeDto } from './dto/photo-like.dto';
import { Roles } from 'src/decorators/roles.decorator';
import { RolesGuard } from 'src/guards/roles.guards';

@ApiTags('Photos')
@Controller('photo')
export class PhotoController {
constructor(private readonly photoService: PhotoService) {}

@ApiOperation({ summary: 'create new photo' })
@Roles('ADMIN')
@UseGuards(RolesGuard)
@Post()
async create(@Body() createPhotoDto: CreatePhotoDto): Promise\<Photo\> {
return this.photoService.create(createPhotoDto);
}
}

Solution

  • In the RolesGuard, the Reflector import should be import { Reflector } from '@nestjs/core';