How To Manage User Roles In Node.js

  Рет қаралды 314,972

Web Dev Simplified

Web Dev Simplified

Күн бұрын

Пікірлер: 298
@cdporgrammer7168
@cdporgrammer7168 4 жыл бұрын
Man I wonder if Kyle actually realises how much he helps us out with his vids man Respect man
@MrEnsiferum77
@MrEnsiferum77 4 жыл бұрын
React kids won't understand u...
@astkh4381
@astkh4381 2 жыл бұрын
@@MrEnsiferum77 реакт тут причем?
@hnasr
@hnasr 4 жыл бұрын
Legend! Love the way you clearly explain these concepts in a simple way. Cheers bro. You are on my recommended channel list on my YT
@AmanNidhi
@AmanNidhi 4 жыл бұрын
i recommend you both on mine
@neon13x
@neon13x 3 жыл бұрын
Legend praising another legend
@kartikjha833
@kartikjha833 3 жыл бұрын
This comment section is pretty legendary
@JD-hq1kn
@JD-hq1kn Жыл бұрын
Ok
@taquiyt
@taquiyt 4 жыл бұрын
pretty much exactly the video I needed for a project. My man web dev simplified is a legend.
@cdporgrammer7168
@cdporgrammer7168 4 жыл бұрын
You get it m8
@sohailkashif6992
@sohailkashif6992 4 жыл бұрын
@@cdporgrammer7168 dear how it connect with mongodb?
@tyrrelldavis9919
@tyrrelldavis9919 4 жыл бұрын
Very true. He is one of the few "bigger" code KZbinrs that has beneficial stuff I've used in real projects
@tyrrelldavis9919
@tyrrelldavis9919 4 жыл бұрын
@@sohailkashif6992 a common cope I would get hit with in boot camp was, "Depends on your use case" Which it actually does. Having a hard time understanding the relationship between a user of the database And A user that is using the site.
@ng4logic
@ng4logic 4 жыл бұрын
this dude is literally a mentor
@mrsmasked180
@mrsmasked180 4 жыл бұрын
You're simply the best out there because you explain your content very well and you go straight to the point, respect man you're a legend !
@pprathameshmore
@pprathameshmore 4 жыл бұрын
Before watching this video, I was creating separate documents for admin and user. Thank you for such a clear explanation tutorial.
@sandVidz
@sandVidz 4 жыл бұрын
I did that and submited lol. Had to pay for that in viva.
@NorteXGame
@NorteXGame 4 жыл бұрын
Never happier when any youtuber uploads
@riadhossain4020
@riadhossain4020 4 жыл бұрын
Kayel your videos are greate for intermediat developers. Clear and simple explanations. Have been following you. You are recommended.
@bedrockcoder5169
@bedrockcoder5169 4 жыл бұрын
*Kyle *great *intermediate
@jmmacatangay_grizzlybear
@jmmacatangay_grizzlybear 4 жыл бұрын
I always keep telling everyone to subscribe to your channel. you're really great really hoping people would recognize you more often.
@ayoubalem865
@ayoubalem865 4 жыл бұрын
7:11 Th res.Status Should be 401 Not 403 401 Means Unauthorized , Forbidden Mean He is Sign Up But he doesn't have the permission to access to the given operation. Thank You btw !
@Study-bt6qh
@Study-bt6qh Жыл бұрын
kakashi hatake😍😍
@tranquility6358
@tranquility6358 4 жыл бұрын
I believe you mixed up the status codes a bit. 401 Unauthorized - send this code when the user is not authorized to view the content (as in the user didn't login) 403 Forbidden - send this code when the user is logged in, but is not allowed to view specific content The difference between these status codes is that 401 should be sent if authorization fails, but proper authorization is possible while 403 is sent when the user is authorized, but doesn't have the required permissions.
@cheetahBeachwood
@cheetahBeachwood 4 жыл бұрын
are you sure? authentication means verifying identity. It gets confusing because the header used to authenticate is called 'authorization' but it is still authentication and 401. authorization means verifying permissions which is 403
@brielov
@brielov 4 жыл бұрын
I agree... 401 is for unauthorized (not logged in) and 403 is forbidden (resource authorization)
@Hadermite
@Hadermite 4 жыл бұрын
@@cheetahBeachwood Yes, he's correct. The title of the status code is a bit messed up, should probably have been "Unauthenticated" instead, it generates a lot of confusion.
@andrejvujic
@andrejvujic 4 жыл бұрын
@Jovan Jevtic jovaneeeee
@eduardonunes1379
@eduardonunes1379 4 жыл бұрын
This video is so motivating since I was taking a break from programming bc of authentication and authorization. Thank you so much!
@ridl27
@ridl27 4 жыл бұрын
such a clear explanation, thank you!
@pavelsokolov4190
@pavelsokolov4190 2 жыл бұрын
Currently I'm learning MEAN and this is exactly what I need for my pet project. Thank you so much for what you're doing!
@ginokoybi7010
@ginokoybi7010 Жыл бұрын
Your video help me too much thanks 🙏
@LabhamJain
@LabhamJain 4 жыл бұрын
You've Successfully Simplified Web For Us. Mission Accomplished 😎
@kmparkhu
@kmparkhu 4 жыл бұрын
Yay!!!!!!!!!!!!!!!!!!! So awesome!!! Thank you !!!! I was just thinking about this because I been following your other tutorials and I love them. I am excited to watch this video.
@T3kKeN9
@T3kKeN9 Жыл бұрын
Awesome video. Concept of modularity with pure functions make this truly scalable.
@MatteoScano
@MatteoScano 11 ай бұрын
Thank you very much. This video... no, all your videos I watched are amazing and helpfull!
@evanmcdaniel5544
@evanmcdaniel5544 4 жыл бұрын
Thanks so much for this. One of the better Node tutorials I've seen.
@jacob.lee380
@jacob.lee380 3 жыл бұрын
Every time I get stuck in something and try to solve a problem by myself. I'm always ended up on your video finding a solution
@jeffmair
@jeffmair 4 жыл бұрын
Your tutorials are top notch Kyle!
@HashimWarren
@HashimWarren 4 жыл бұрын
Love the progression in this video. Super clear
@pedro_jaber9357
@pedro_jaber9357 Жыл бұрын
OMG! thank you. I believe in Web Dev Simplified supremacy!!!!!
@swibay
@swibay 4 жыл бұрын
My name is Kyle and my job is to simplify the web for you! Your tutorials are always gre8!
@ononaokisama
@ononaokisama 3 жыл бұрын
Literally god tier content
@joel9909
@joel9909 4 жыл бұрын
Just found your channel, loving it so far.
@yabu_ai
@yabu_ai Жыл бұрын
This is the best video about role based authentication...Thanks
@dthoma128
@dthoma128 4 жыл бұрын
Kyle ... great tutorial ... very glad I found your channel! Thank you.
@HurikaneTv
@HurikaneTv 3 жыл бұрын
Kyle ... One Word: Genius
@rfossella
@rfossella 4 жыл бұрын
As usual, great video - clear, concise and immediately usable. Thanks!
@stylesoftware
@stylesoftware 4 жыл бұрын
Awesome, helped me with some of my lingering middleware integration ignorance. Well explained!
@apurvsawant5703
@apurvsawant5703 4 жыл бұрын
Exactly the video I needed. Thanks man.
@feminjustin2478
@feminjustin2478 4 жыл бұрын
you explain things so simply....easy to follow.....
@Hrit
@Hrit 2 жыл бұрын
Enjoyed the turotial throughly!
@taherr1341
@taherr1341 3 жыл бұрын
Awesome. You are the best. I wonder who could be so unfair to dislike it?
@tbg6nb
@tbg6nb 17 күн бұрын
20:31 does it make sense in practice ? I'm pretty sure an admin should have right to delete any project
@sapnilpatel1645
@sapnilpatel1645 2 жыл бұрын
Your video helps me a lot. I really appreciate your effort. Thank you so much!
@jodufan8754
@jodufan8754 3 жыл бұрын
I would recommend to assign every role an int so you can calculate up and downwards ! Edit: To calculate the inheritance of the groups if given!
@montasirmahmud3585
@montasirmahmud3585 2 жыл бұрын
Why ? explain briefly please..
@jodu
@jodu 2 жыл бұрын
@@montasirmahmud3585 Then you can just use bit calculations to check if a role is hierarchically over another role or not by for example using >=
@harleyspeedthrust4013
@harleyspeedthrust4013 2 жыл бұрын
I've got a permission system where the permissions are strings like "mail.create" or "mail.*". Each user has an array of permissions, and the permission strings are referenced in a POJO that maps object keys to permission names. So if you have an endpoint that should be accessible to anyone with a mail permission, you call `hasAnyPermission(req.user, Permissions.mail)` where Permissions.mail is an object containing more fine-grained permissions, and that endpoint would be accessible to anybody with a "mail.(whatever)" permission. "*" is a wildcard that refers to all sub-permissions, so if someone has the permission "*" then they're a superuser, and if they have the permission "boards.*" then they can do anything on any image board. There are some functions, like `hasAnyPermission` or `hasPermission` that you stick at the beginning of your route handler to enforce the permissions. Of course you don't have to put them at the beginning of your route handler - the entire frontend of the app is handlebars so I also use them on specific pages where I want to display some items/links but each link requires a separate permission. I'm actually pretty surprised that I've made it this far using only handlebars and plain JS for the frontend. The backend is NodeJS with Typescript which is great but I've managed to write a multiplayer FPS almost entirely in plain JS (server-side is that typescript nodejs I just mentioned) and build a forum engine and now I've set up a mail server and a way for users to create and manage email addresses on my domain. handlebars may not be flashy but damn if I like it
@bilza2023
@bilza2023 Күн бұрын
why ??? why not use the already available libraries?
@harleyspeedthrust4013
@harleyspeedthrust4013 Күн бұрын
@bilza2023 because modern javascript use-libraries-for-everything culture is cancer
@OnlyJavascript
@OnlyJavascript Жыл бұрын
please make a complete node course for beginners to intermediate level and an advanced node course too. We are ready to buy it. Please vote if u guys need it too.
@vinhubcompters
@vinhubcompters 3 жыл бұрын
best teacher ever
@juliecherner9085
@juliecherner9085 Жыл бұрын
Thank you for such an amazing tutorial!
@omar9987
@omar9987 4 жыл бұрын
It would be awesome if you could create like a mini blog[or anything] with react & express that uses user-based roles. I'm trying to add user based rules to my react app :p
@williamxu2402
@williamxu2402 3 жыл бұрын
Thank you very much! This is exactly what I needed for my project!
@adithyasanthosh30
@adithyasanthosh30 4 жыл бұрын
Nice. Introductory tutorial on how to manage user roles.
@virgiliogervacioestadillo1389
@virgiliogervacioestadillo1389 3 жыл бұрын
Thank you so much Kyle. I found this very helpful.
@nitindaphale2008
@nitindaphale2008 2 жыл бұрын
Very good explained , Love from India.
@saisaske1
@saisaske1 4 жыл бұрын
Just want to say thankyou man. Words are short here.
@coanjos
@coanjos 4 жыл бұрын
This video came in the perfect time. Thank you!
@TheBabelian
@TheBabelian 2 жыл бұрын
wow! such a great tutorial. thanks for the guide!
@a1225johnny
@a1225johnny 3 жыл бұрын
very clear, it’s helpful in my project. Thanks a lot
@thejasong01
@thejasong01 4 жыл бұрын
YOU ARE AWESOME thankyou for putting great content, with fast but effective and SIMPLE :)
@omrimaher2754
@omrimaher2754 2 жыл бұрын
Really amazing explanation!
@smsibasish
@smsibasish 4 жыл бұрын
Great content. Would love to see an elaborated version of this with more of a real world scenarios where an user can have multiple role for different context.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Really all you need to do is make the user.role property an array and then check if the role is in the array or not.
@smsibasish
@smsibasish 4 жыл бұрын
@@WebDevSimplified I feel that will create some problem. Let me explain with your example. Say I introduce two new roles project viewer and project admin. Now one user can be project viewer for one project and project admin for another. If I model my user to have an array of roles then how do I keep track of which project he is an admin of.
@mrviometal4948
@mrviometal4948 4 жыл бұрын
@@smsibasish I think you can simply tie the role to the project, meaning your DB entry can look like this: Projects: [ { id:1, name:"first project", userId: 1, userRole: canView}, ... ] then you check for the user's role with its id to distinguish between what can be viewed and what can be edited, deleted or updated but what case should require something like that?
@smsibasish
@smsibasish 4 жыл бұрын
@@mrviometal4948 consider this example. A user can be part of many groups and a group may contain a few user. A user can be a admin of few groups but member of other groups. In that case what should be the role of the user in User model and should the Group model have the admin and member fields separately.
@mrviometal4948
@mrviometal4948 4 жыл бұрын
@@smsibasish I see, I think it can be solved by an abstraction between admin and view. i.e. any admin can view, but not any viewer can be an admin. And so, the edit and delete have to be from an admin or the respective user of the project. But the project entries can contain an array of users who can view...i.e. => Projects: [ { id:1, name:"first project", userId: 1, usersWhoCanView: [2,3,4,5...]}, ... ] so in the implementation of the can view, we can look up the array if it contains the signed-in user's id. In this case, those who can view are (Admins, People who create the project i.e. userId, and any user in the array) Does that make sense?
@mayank_singh_43
@mayank_singh_43 2 жыл бұрын
This is what i want , u are awesome sir 🤘🤘🤘
@mamusthafa6
@mamusthafa6 2 жыл бұрын
YOu are amazing... Really simplified complex things
@geld5220
@geld5220 2 жыл бұрын
too good. I did a version in typescript but followed your flows. Thanks
@user-ww6ns4hn9r
@user-ww6ns4hn9r 2 жыл бұрын
mmh, i think there is some confusion between permissions and actually filtering the correct data. One thing is permission based on levels (the higher level, the higher the privilege to see things), and one things is to filter the correct projects for the user. wouldn't that be a filter applied at DAO level which returns the right data rather than crammining into the permissions? Permission after all should be agnostic to the kind of data you are handling, and should worry only about roles . correct me if I am wrong?
@dpolo567
@dpolo567 2 жыл бұрын
Thanks for the great tutorial. In the end, I'm just wondering (if we work with real data obtained from the database), what is the best way to filter the data (in this case the scopedProjects function). If we have a lot of data, in this case we need to fetch all of them and then filter them. Isn't it better (in terms of performance) to check the role first and then pull only specific (filtered on db query level) data from the database?
@mcmuffin1258
@mcmuffin1258 3 жыл бұрын
If someone knows someone else's userId there could be problems. How do we make sure someone cant modify userId in the request?
@zlatan1261
@zlatan1261 3 жыл бұрын
This is the question that worries me as well
@navan1087
@navan1087 3 жыл бұрын
use jwt short lived token
@nirahhp999
@nirahhp999 2 жыл бұрын
could please create a video on RBAC in MySQL with limited permissions to API in nodejs
@bulldog2024
@bulldog2024 3 жыл бұрын
You could have a super admin that would have the ability to delete any project. If an employee is no longer working for the company, you might want to have someone either delete that employee's project or reassign them to another user to complete.
@BBI-Brandboost
@BBI-Brandboost 4 жыл бұрын
Thanks for sharing, it is nice and easy to follow which is a massive help.
@thedevlife
@thedevlife 4 жыл бұрын
Great content. Gives motivation to keep our channel going.
@agasthya3693
@agasthya3693 4 жыл бұрын
Hey Kayle please do video on Gulp, Grunt, webpack and parcel & when to choose which tool
@medAmineRg
@medAmineRg 3 жыл бұрын
that was a great video thankyou so much!
@RuiLopesFR
@RuiLopesFR 3 жыл бұрын
Nice one - Just for the sake of DRY : scopedProjects = (user, projects) => projects.filter(project => canViewProject(user, project))
@Sandeep-lb7wb
@Sandeep-lb7wb 4 жыл бұрын
could you please explain how to set admin role to the users who are registers first
@rafishaaya1658
@rafishaaya1658 2 жыл бұрын
great video though, would that be useful for a management systems as well?
@danial9864
@danial9864 3 жыл бұрын
Thank you so much for the tutorial video it's quite informative and professional
@MrAlliqator
@MrAlliqator 3 жыл бұрын
Please make video how can create front side
@larita182-x1k
@larita182-x1k 3 жыл бұрын
THANK YOUUUUUUUUUUU!!!!!! I finally understand this.
@ayushthakur733
@ayushthakur733 3 жыл бұрын
So accurate with the name web dev SIMPLIFIED
@Millonerium
@Millonerium Жыл бұрын
great video bro, please do a MERN project like this with frontend
@-Nandakishore-wt5is
@-Nandakishore-wt5is 3 жыл бұрын
Hi can you make a video for multiple type accounts using mern stack , for example there are two types of users regular users, product manufacturers, from which we will take different information from both of them. But we need to allow them to login from same page. Is it possible ?
@josephlivengood4508
@josephlivengood4508 3 жыл бұрын
You dont view anything in the browser? I'm using the ejs view engine and am having problems getting the ._id from mongodb to verify that the user is the owner of a post. I cannot find a work around. Maybe this would do it 🤔
@mikexue5104
@mikexue5104 3 жыл бұрын
it's 2021, so there is still NO out-of-box user /role management extension for Nodejs?
@nirmesh44
@nirmesh44 4 жыл бұрын
Perfect. Very nicely done
@mallusrgreat
@mallusrgreat 3 жыл бұрын
Kyle to webcam: Focus on my hair not the content
@awatanshpratapsingh120
@awatanshpratapsingh120 3 жыл бұрын
How to add the functionality in which admin can change the roles .
@hindbensafi4646
@hindbensafi4646 2 жыл бұрын
Thanks a lot ! great video ! Please how can i protect my front-end routes using those APIs ? For example, when users login, the Admin would have route to the admin page but normal users not ? is it secure to check roles in the front-end ?
@ashiqsultanmohamed9765
@ashiqsultanmohamed9765 4 жыл бұрын
I recently deployed an express middle ware which exactly does this. Check route-access-control npm package
@paularah8877
@paularah8877 4 жыл бұрын
will check it out, thanks!
@alex_lomov
@alex_lomov 4 жыл бұрын
Great layout of material.
@billythemusical
@billythemusical 3 жыл бұрын
Hey! Thanks for the video, although I don't think the PROMO code works anymore 😩
@bigbeeforever
@bigbeeforever 4 жыл бұрын
surely on signup you wouldnt have a choice of role, so how would you assign the ADMIN role other than everyone is BASIC. would this be done in the backend?
@harshjindal5179
@harshjindal5179 4 жыл бұрын
hlo can u tell me how to compile and run this application ?
@edisvelicanin8854
@edisvelicanin8854 4 жыл бұрын
exactly what i was looking for
@chriisduran
@chriisduran 3 жыл бұрын
This lesson is great, just I would like add more basic users, the problem is that this example define the basic users from start What if i have a login that any users want to access? How define that all users logged with no id admin are basic? I´m stuck in that! :(
@iurii7752
@iurii7752 4 жыл бұрын
The best educational videos
@indigosay
@indigosay 4 жыл бұрын
I added this video to my Gold Collection
@pankaj_9998
@pankaj_9998 3 жыл бұрын
Thank you. This was a great learing experience.
@alexandre3932
@alexandre3932 4 жыл бұрын
Good tutorial, why sometimes did you use es6 and sometimes not ?
@rishabsharma5307
@rishabsharma5307 3 жыл бұрын
Awesome video
@matiasmanevi1521
@matiasmanevi1521 4 жыл бұрын
How would you share the permissions logic between the node backend and a ... lets say, react frontend?
@alikashif8098
@alikashif8098 Жыл бұрын
I am bit concerned with the performance of approach explained here, users are in some DB, say mongo or SQL, so are the roles and permissions, with this approach , on each call, I have to go to DB and verify that sent userId is valid(login basic Auth) and then proceed next middleware, and that middleware will again call the DB and look for role permissions on particular object (currently handelled with static data.js), thus with each request multiple calls to DB are being made. now consider an application with good amount of users intracing, Can you please shed some light on performance perspective?
@BabasolaOso
@BabasolaOso 3 ай бұрын
I love you and PedroTech, both kinda feel alike to me
@amitshrestha898
@amitshrestha898 4 жыл бұрын
Found what I am looking for thanks.
@zlatan1261
@zlatan1261 3 жыл бұрын
After all, this method does not meet the requirements of security. The role is taken from the body. If I release basic instead of admin in the header, you will send the relevant information to the admin from the server. is that right?
@bunnybloods768
@bunnybloods768 4 жыл бұрын
You are so great.can you tell me what is your main job besides youtube?
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I am a fullstack web developer consultant.
@swapnilkuwar7040
@swapnilkuwar7040 4 жыл бұрын
What if we create capabilities for each action, and then assign that capability to the roles so that one capability can be assign to the multiple roles.
@shabbirjodhpurwala6979
@shabbirjodhpurwala6979 Жыл бұрын
I researched about this Adding body to get request is bad practise Isn't it?? Also if caching is used it would cause weird bugs..because caching mechanism usually ignore the get body Is this right?? What is the correct way to go about it??
JWT Authentication Tutorial - Node.js
27:36
Web Dev Simplified
Рет қаралды 1 МЛН
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 498 М.
OCCUPIED #shortssprintbrasil
0:37
Natan por Aí
Рет қаралды 131 МЛН
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН
Nodefusion Company Profile - Customers Edition
8:25
Nodefusion
Рет қаралды 1
How is this Website so fast!?
13:39
Wes Bos
Рет қаралды 1,3 МЛН
MySQL Node.js Express
28:03
Sam Meech-Ward
Рет қаралды 216 М.
How to Manage User Roles in NextJS / NodeJS
12:11
Josh tried coding
Рет қаралды 122 М.
Discord Made The Coolest CSS Only Input Animation
17:48
Web Dev Simplified
Рет қаралды 74 М.
Redis Crash Course
27:31
Web Dev Simplified
Рет қаралды 662 М.
How To Build Feature Flags Like A Senior Dev In 20 Minutes
20:33
Web Dev Simplified
Рет қаралды 116 М.
Learn Express JS In 35 Minutes
36:03
Web Dev Simplified
Рет қаралды 883 М.
OCCUPIED #shortssprintbrasil
0:37
Natan por Aí
Рет қаралды 131 МЛН