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 guards - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Applying global guards
Applying guards globally in a NestJS application ensures that the guard is executed for every route handler in the application. Basically, there are two ways to apply the guards globally. First way is to configure the guard inside the app module file. So here, let me open the module file and inside the providers array, I'll give the curly braces, which is also known as the providers object in NestJS. This providers object is used for defining more advanced configuration settings, like the provide property. This property takes a token value. Now there are various predefined token values which can be passed to the provide property. As we are dealing with guards, I'll give the app guard token. This app guard is a special token that NestJS recognizes for global guards. So with this, we are telling NestJS that we want to apply a guard on the module level that is global level. Now to give the guard name, we will use another property called use class. This property specifies the guard class…
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 guards4m 14s
-
(Locked)
Understanding guard5m 33s
-
(Locked)
Understanding ExecutionContext6m 50s
-
(Locked)
Accessing arguments with getArgs()3m 42s
-
(Locked)
Limiting controller access with guard4m 6s
-
(Locked)
Understanding switchToHttp() method4m 59s
-
(Locked)
Assignment: API key authorization6m 10s
-
(Locked)
Applying multiple guards3m 14s
-
(Locked)
Defining custom metadata5m 6s
-
(Locked)
Setting custom metadata: A better way3m 25s
-
(Locked)
Applying role for specific handlers10m 3s
-
(Locked)
Applying multiple roles1m 35s
-
(Locked)
Applying global guards4m 46s
-
(Locked)
-
-
-
-
-
-
-