Рутовый модуль
@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')