R
R
Rag'n' Code Man2021-08-15 18:58:25
Node.js
Rag'n' Code Man, 2021-08-15 18:58:25

How to inject JwtService in AuthorizationGuard (NestJS)?

I have some AuthorizationGuard

@Injectable()
export class AuthGuard implements CanActivate {
  canActivate(
    context: ExecutionContext,
  ): boolean | Promise<boolean> | Observable<boolean> {
    return false
  }
}

Authorization works on JWT, and for this NestJS has a special module JwtModulethat contains JwtService.

I need to inject this service into my Guard, but since it is not and cannot be part of any module, I cannot do it by simply inserting a constructor

constructor(private readonly JwtService: JwtService) {}


The question is how to inject a service belonging to a module in Guard?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question