#How to use reflectors inside interceptor

24 messages · Page 1 of 1 (latest)

edgy cradle
#

Im trying to use a custom decorator to configure the behavior of my interceptor but it appears no to be working.

ERROR [ExceptionHandler] Nest can't resolve dependencies of the SchoolInterceptor (?, RedisManager). Please make sure that the argument Object at index [0] is available in the AppModule context.

interceptor.ts

@Injectable()
export class SchoolInterceptor implements NestInterceptor {
  constructor(
    private reflector: Reflector,
    private readonly redisService: RedisService,
  ) {}
}

decorator.ts

import { SetMetadata } from '@nestjs/common';

export const IGNORE_JWT_VERIFICATION_KEY = 'ignoreJwtVerification';
export const IgnoreJwtVerification = () =>
  SetMetadata(IGNORE_JWT_VERIFICATION_KEY, true);

zenith lintel
#

did you import that Reflector from @nestjs/core?

edgy cradle
#

yes

#
import { Reflector } from '@nestjs/core';
zenith lintel
#

can you run npx nest info

edgy cradle
#
[System Information]
OS Version     : Windows 10
NodeJS Version : v16.17.0
NPM Version    : 9.6.5

[Nest CLI]
Nest CLI Version : 10.0.3

[Nest Platform Information]
platform-express version : 10.0.3
mapped-types version     : 2.0.0
schematics version       : 10.0.1
mongoose version         : 10.0.0
schedule version         : 3.0.1
testing version          : 10.0.3
common version           : 10.0.3
config version           : 3.0.0
core version             : 10.0.3
cli version              : 10.0.3
#

pq a gente ta falando em ingles ?

#

kkkkk

zenith lintel
edgy cradle
#

n sabia q tinha um ch pra pt, mal

zenith lintel
#

try this @Inject(Reflector) private reflector: Reflector,

edgy cradle
#

it worked

#

any idea of what was causing the problem?

zenith lintel
#

nop

edgy cradle
#

or why it fixed?

#

weird 🤔

#

these 2 approaches should have the same behavior, right?

zenith lintel
#

if you manage to write a minimum reproduction of that, I'd take a look

edgy cradle
#

i can try

zenith lintel
#

can you show us all the file import statements you have in the file of your interceptor?

dull sapphire
#

Same issue here