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 multiple roles - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Applying multiple roles
In some applications, it is necessary to assign multiple roles to users to ensure that they have the appropriate permissions based on their responsibilities. In order to provide multiple roles on the route, we just have to update the roles decorator. For example, let's give the user role to the post route handler. Now, when we try to make a POST request as a user, I'll give the API key user B102 and the user is added. Let's make the GET request as well to check the new user giving the API key as user D104 and the user data is displayed. So this is how we can provide multiple roles to a route handler. Now few things to remember when giving multiple roles is in the roles.decorator file, we have to provide the role enum of type array. Because then only we can assign multiple roles on a route handler. Also even if we give the role enum as array and do not provide the spread operator, then you can see the error expected one argument but got two. So again, we cannot provide multiple roles…
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)
-
-
-
-
-
-
-