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.
Introduction to guards - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Introduction to guards
Guards are one of the most important and core concepts in NestJS. Their sole purpose is to guard the application routes, that is, request endpoints, by examining the incoming requests and deciding whether to allow or deny access based on certain conditions. Guards are used for tasks like checking if a user is logged in, determining if a user has the right permissions, or validating incoming data before processing it. Now you may think that middleware can easily handle the authorization and authentication which it does, if the application is built on traditional ExpressJS. But in NestJS, we have guards and middleware by nature is a bit dumb. What I mean to say is, it does not know which handler will be executed after calling the next function. Like here in the code, middleware will not be able to process what will happen after it passes the request to the next handler. It only knows its own job, which is to examine the request and make a decision based on that. After that, it's up to…
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)
-
-
-
-
-
-
-