NestJS Role Based Authorization | RBAC
In this video we set up Role Based Authorization to guard our end points. We create a custom decorator and guard. Role Based Access Control or RBAC builds up on authentication (previous video) by protecting the routes based on the user type i.e. Admin, Premium, User.
--------------------------------------------------
Recommended Udemy courses
--------------------------------------------------
NestJS - Zero to Hero: tinyurl.com/3rxsz669
Angular - The Complete Guide: tinyurl.com/4h5rmpsj
Understanding TypeScript: tinyurl.com/9wz6fp7k
React - The Complete Guide: tinyurl.com/2t6v5yeu
Docker Mastery (with Kubernetes + Swarm): tinyurl.com/yeymdnhn
Playlist: • LinkedIn Clone - Ionic...
GitHub: github.com/Jon-Peppinck/linke...
Пікірлер: 42
This whole Nest series is absolute gold mate. Fantatstic stuff. Thanks.
@JonPeppinck
2 жыл бұрын
Thanks so much mixxxer! Glad you have been liking it so far. Big fan of NestJS after working with Angular, Java, and Node.
Amazing work! Thank you so much for making this.
@JonPeppinck
Жыл бұрын
Thanks so much for watching! Cheers!
Great tutorial.Thank you for sharing!
@JonPeppinck
2 жыл бұрын
Thanks so much Hollyn - I'm glad it was helpful!
This video very helpful, from Vietnam with love
@JonPeppinck
2 жыл бұрын
Thank you Hieu! Glad it helped. I've been to Halong Bay before. It was wonderful
This video got me pumping great stuff!
@JonPeppinck
3 жыл бұрын
Thank you very much. I'm glad you are pumping. Pump city!
Thank you for this video. Very clearly explained!
@JonPeppinck
2 жыл бұрын
Awesome! Thanks so much!
thanks a lot bro, so useful
@JonPeppinck
2 ай бұрын
Thanks so much for checking it out!
Hello from Brazil, this video is amazing.
@JonPeppinck
2 жыл бұрын
Thanks so much Rodrigo!
It's worked!!! Thank you so much ♥
@JonPeppinck
Жыл бұрын
Awesome, nice stuff!
Another great video!
@JonPeppinck
2 жыл бұрын
Thanks Marco! You are doing a great job working through the series.
Hey, i have been receiving this folow exception: [Nest] 11656 - 16/02/2022 16:36:25 ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'role') can you give a tip about the problem?
great !
@JonPeppinck
2 жыл бұрын
Thanks Gia!
you awsome
@JonPeppinck
2 жыл бұрын
Thanks so much tris!
superb explanation !! i miss out n one thing , what makes the guard throw 403 forbidden error , as we are not specifying it anywhere :)
@JonPeppinck
2 жыл бұрын
Thank you Yog! I believe it is because the roles guard implements CanActivate, which enforces the canActivate method to be called when we use the guard. From reading through the documentation, it is inferred that there is some code built into NestJS's common library which controls this behaviour. When a user with insufficient privileges requests an endpoint, Nest automatically returns a 403. If you want to return a different error response, you should throw your own specific exception instead of returning a boolean value.
how can this project be deployed?
Thanks a lot, it was very helpful for me! One minor remark on 23:49 it can be done more simply. Just use includes directly on requiredRoles array, should be like this requiredRoles.includes(user.role). It will also work.
@JonPeppinck
2 жыл бұрын
Thanks Tapac. Glad it was helpful. You are right, that is better. Thanks for pointing that out.
I'm confused, how to make someone admin?? I logged in using all accounts but none of them are admin, how to make one?
@JonPeppinck
Жыл бұрын
Probably easiest to just go to the pg database and change the account type to admin for a particular user.
@saurabhsinha3319
Жыл бұрын
@@JonPeppinck Thanks so much
why should we return true if not requiredRoles?
@JonPeppinck
Жыл бұрын
18:19
@JonPeppinck
Жыл бұрын
The roles guard works in conjunction with the role decorator. If the role annotations are removed by the programmer, it is assumed that you don't want to protect the end point by the role.
@andideveloper8345
Жыл бұрын
@@JonPeppinck thank you for your answer, can you do a tutorial implementing middleware + guard + interceptors using best practices, a simple system where a user can login based on roles like: guest,admin,manager and this roles are updated from the main ADMIN.
Please turn your mic arround and speak into the right side xD
@JonPeppinck
2 жыл бұрын
I was doing that. I have been meaning to buy a good mic for some time though.
@GamingClubGermany
2 жыл бұрын
@@JonPeppinck oh sounded Like you were speaking in to the wrong Side my appologise :). Sounds exaclty that way thats why haha. What mic do you have?
previous video : kzread.info/dash/bejne/g6CDxrixnZjAltY.html
dark mode PLEASE