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.
Assignment: API key authorization - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Assignment: API key authorization
In this assignment, we are going to create a guard that allows user authorization on the basis of the API key assigned to the object. The request should proceed if the user inputs correct API key assigned to the object. Otherwise, for incorrect API key value, the request should not be processed, and an unauthorized error should be displayed. So let's get started. I will create a service file by giving the command nest generate service slash services, naming the service file as user. Inside the user service, I will create a user's array object. I'll set the API key as property and will assign a secret API key. Then a name property with a name value. and an email property with an email value. I'll create two more objects user B and user C. Then I'll create a method naming it as get user and passing the API key as a parameter which is of type string. We will retrieve the user data based on the API key. So inside this method, let me give return this.users.find. In the callback, I'll pass…
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)
-
-
-
-
-
-
-