@hryashik

Почему нет доступа к reflector?

Рутовый модуль
@Module({
  imports: [
    ...
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
  ],
})
export class AppModule {}


Сам Guard
Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') implements CanActivate {
  constructor(
    private readonly reflector: Reflector,
    private readonly authService: AuthService,
    private readonly userRepository: UsersRepositoryService
  ) {
    super();
  }
  public async canActivate(context: ExecutionContext): Promise<boolean> {
    console.log(this.reflector)
    const secured = this.reflector.get('secured', context.getHandler());
    if (!secured) return true;
    return false
  }
}

TypeError: Cannot read properties of undefined (reading 'get')
  • Вопрос задан
  • 59 просмотров
Пригласить эксперта
Ответы на вопрос 1
Grapeoff
@Grapeoff
В чём концепция...?
Потому что его нужно импортировать в модуль.

@Module({
  imports: [
    Reflector,
    ...
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
  ],
})
export class AppModule {}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы