NestJS · Middle · Question 5 of 75

How do you register a global guard that can inject other providers?

providers: [{ provide: APP_GUARD, useClass: JwtAuthGuard }]

Explanation

app.useGlobalGuards() takes an instance created outside the DI container, so its dependencies aren't injected. APP_PIPE, APP_INTERCEPTOR and APP_FILTER work the same way.

Further reading

Problem with a question

NestJS · Middle · question 5

Test yourself

Take the NestJS · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz