From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Applying global interceptors - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Applying global interceptors
Just like the pipes and guards, interceptors can either be controller scoped, method scoped, or global scoped. Applying interceptors globally ensures that the interceptor is applied on every single route handler in the application. There are two ways to apply global interceptors. First way is to configure the interceptor inside the app module file. So, let me open the app module file and inside the providers array, I will give the curly braces that is known as the providers object. We have already seen what is the use of providers object in the previous section. Inside this object, I will give the provide property which takes a token value predefined by NestJS. As we want to register the interceptor globally, I will give the token app underscore interceptor and along with the token we also have to specify the interceptor class by using the use class property and the class name that is AuthInterceptor. That's it. So, this AppInterceptor is special token that NestJS recognizes for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Introduction to interceptors3m
-
(Locked)
Understanding interceptor5m 54s
-
(Locked)
Assignment: Transforming response data4m 42s
-
(Locked)
Assignment: Modifying request headers3m 49s
-
(Locked)
Assignment: Hiding sensitive information5m 50s
-
(Locked)
Exception mapping3m 23s
-
(Locked)
Data validation with interceptor5m 37s
-
(Locked)
Authentication and authorization4m 24s
-
(Locked)
Applying global interceptors2m 39s
-
(Locked)
-
-
-
-
-
-