How To Manage User Roles In Node.js

Sdílet
Vložit
  • čas přidán 28. 07. 2024
  • 🚨 IMPORTANT:
    1 Year Free Hosting: www.atlantic.net/webdevsimpli...
    Use code KYLE for an additional $50
    User permission systems are the core of nearly every application. From Reddit to accounting every site needs to manage user permissions, but that is much easier said than done. In this video I will be showing you exactly how to set up a flexible and robust user permission system which you can use in any Node.js application.
    📚 Materials/References:
    Starting GitHub Code: github.com/WebDevSimplified/n...
    Ending GitHub Code: github.com/WebDevSimplified/n...
    HTTP Status Codes Tutorial: • Learn HTTP Status Code...
    🧠 Concepts Covered:
    - How to handle user auth in Node.js
    - How to create flexible user permissions in Node.js
    - How to manage scoped routes in Node.js
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    #Node.js #WDS #UserPermissions

Komentáře • 294

  • @hnasr
    @hnasr Před 4 lety +242

    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 Před 4 lety +8

      i recommend you both on mine

    • @neon13x
      @neon13x Před 3 lety +7

      Legend praising another legend

    • @kartikjha833
      @kartikjha833 Před 2 lety +2

      This comment section is pretty legendary

    • @JD-hq1kn
      @JD-hq1kn Před 11 měsíci

      Ok

  • @cdporgrammer7168
    @cdporgrammer7168 Před 4 lety +137

    Man I wonder if Kyle actually realises how much he helps us out with his vids man
    Respect man

    • @MrEnsiferum77
      @MrEnsiferum77 Před 4 lety

      React kids won't understand u...

    • @astkh4381
      @astkh4381 Před 2 lety

      @@MrEnsiferum77 реакт тут причем?

  • @eduardonunes1379
    @eduardonunes1379 Před 4 lety +4

    This video is so motivating since I was taking a break from programming bc of authentication and authorization. Thank you so much!

  • @mrsmasked180
    @mrsmasked180 Před 4 lety +17

    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 !

  • @ridl27
    @ridl27 Před 4 lety +12

    such a clear explanation, thank you!

  • @taquilol
    @taquilol Před 4 lety +132

    pretty much exactly the video I needed for a project. My man web dev simplified is a legend.

    • @cdporgrammer7168
      @cdporgrammer7168 Před 4 lety +1

      You get it m8

    • @sohailkashif6992
      @sohailkashif6992 Před 4 lety +1

      @@cdporgrammer7168 dear how it connect with mongodb?

    • @tyrrelldavis9919
      @tyrrelldavis9919 Před 4 lety +1

      Very true.
      He is one of the few "bigger" code CZcamsrs that has beneficial stuff I've used in real projects

    • @tyrrelldavis9919
      @tyrrelldavis9919 Před 4 lety +1

      @@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 Před 3 lety

      this dude is literally a mentor

  • @HashimWarren
    @HashimWarren Před 4 lety +1

    Love the progression in this video. Super clear

  • @evanmcdaniel5544
    @evanmcdaniel5544 Před 3 lety

    Thanks so much for this. One of the better Node tutorials I've seen.

  • @T3kKeN9
    @T3kKeN9 Před rokem

    Awesome video. Concept of modularity with pure functions make this truly scalable.

  • @jmmacatangay_grizzlybear
    @jmmacatangay_grizzlybear Před 4 lety +1

    I always keep telling everyone to subscribe to your channel. you're really great really hoping people would recognize you more often.

  • @kmparkhu
    @kmparkhu Před 4 lety +1

    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.

  • @stylesoftware
    @stylesoftware Před 4 lety +1

    Awesome, helped me with some of my lingering middleware integration ignorance. Well explained!

  • @pavelsokolov4190
    @pavelsokolov4190 Před 2 lety +1

    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!

  • @dthoma128
    @dthoma128 Před 4 lety

    Kyle ... great tutorial ... very glad I found your channel! Thank you.

  • @coanjos
    @coanjos Před 4 lety

    This video came in the perfect time. Thank you!

  • @NorteXGame
    @NorteXGame Před 4 lety +4

    Never happier when any youtuber uploads

  • @joel9909
    @joel9909 Před 3 lety

    Just found your channel, loving it so far.

  • @rfossella
    @rfossella Před 4 lety +3

    As usual, great video - clear, concise and immediately usable. Thanks!

  • @williamxu2402
    @williamxu2402 Před 2 lety

    Thank you very much! This is exactly what I needed for my project!

  • @jeffmair
    @jeffmair Před 4 lety

    Your tutorials are top notch Kyle!

  • @thejasong01
    @thejasong01 Před 4 lety

    YOU ARE AWESOME thankyou for putting great content, with fast but effective and SIMPLE :)

  • @riadhossain4020
    @riadhossain4020 Před 4 lety +1

    Kayel your videos are greate for intermediat developers. Clear and simple explanations. Have been following you. You are recommended.

  • @sapnilpatel1645
    @sapnilpatel1645 Před rokem

    Your video helps me a lot. I really appreciate your effort.
    Thank you so much!

  • @a1225johnny
    @a1225johnny Před 3 lety

    very clear, it’s helpful in my project. Thanks a lot

  • @BBI-Brandboost
    @BBI-Brandboost Před 4 lety

    Thanks for sharing, it is nice and easy to follow which is a massive help.

  • @virgiliogervacioestadillo1389

    Thank you so much Kyle. I found this very helpful.

  • @apurvsawant5703
    @apurvsawant5703 Před 3 lety

    Exactly the video I needed. Thanks man.

  • @danial9864
    @danial9864 Před 3 lety

    Thank you so much for the tutorial video it's quite informative and professional

  • @pprathameshmore
    @pprathameshmore Před 4 lety +1

    Before watching this video, I was creating separate documents for admin and user. Thank you for such a clear explanation tutorial.

    • @sandVidz
      @sandVidz Před 4 lety +1

      I did that and submited lol. Had to pay for that in viva.

  • @adithyasanthosh30
    @adithyasanthosh30 Před 4 lety

    Nice. Introductory tutorial on how to manage user roles.

  • @feminjustin2478
    @feminjustin2478 Před 4 lety

    you explain things so simply....easy to follow.....

  • @LabhamJain
    @LabhamJain Před 4 lety +1

    You've Successfully Simplified Web For Us. Mission Accomplished 😎

  • @taherr1341
    @taherr1341 Před 3 lety

    Awesome. You are the best. I wonder who could be so unfair to dislike it?

  • @TheBabelian
    @TheBabelian Před 2 lety

    wow! such a great tutorial. thanks for the guide!

  • @pankaj_9998
    @pankaj_9998 Před 3 lety

    Thank you. This was a great learing experience.

  • @thedevlife
    @thedevlife Před 4 lety +1

    Great content. Gives motivation to keep our channel going.

  • @juliecherner9085
    @juliecherner9085 Před rokem

    Thank you for such an amazing tutorial!

  • @yabtsegayeshidnber5226

    This is the best video about role based authentication...Thanks

  • @omar9987
    @omar9987 Před 4 lety +7

    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

  • @swibay
    @swibay Před 4 lety +1

    My name is Kyle and my job is to simplify the web for you!
    Your tutorials are always gre8!

  • @user-qo3fu1lb2l
    @user-qo3fu1lb2l Před 5 měsíci

    Thank you very much. This video... no, all your videos I watched are amazing and helpfull!

  • @saisaske1
    @saisaske1 Před 3 lety

    Just want to say thankyou man. Words are short here.

  • @thinkdomotic4915
    @thinkdomotic4915 Před 4 lety

    Great content, very helpful, thanks lots

  • @nfaical3
    @nfaical3 Před 3 lety

    Thank you very much , as always easy explanations.
    Please add how to protect the server from attacks like ddos and brute force attack.

  • @ginokoybi7010
    @ginokoybi7010 Před 11 měsíci +1

    Your video help me too much thanks 🙏

  • @Hrit
    @Hrit Před rokem

    Enjoyed the turotial throughly!

  • @medAmineRg
    @medAmineRg Před 2 lety

    that was a great video thankyou so much!

  • @geld5220
    @geld5220 Před 2 lety

    too good. I did a version in typescript but followed your flows. Thanks

  • @tranquility6358
    @tranquility6358 Před 4 lety +47

    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.

    • @ArthurCowdery
      @ArthurCowdery Před 4 lety +1

      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 Před 4 lety +10

      I agree... 401 is for unauthorized (not logged in) and 403 is forbidden (resource authorization)

    • @Hadermite
      @Hadermite Před 4 lety +4

      @@ArthurCowdery 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 Před 4 lety

      @Jovan Jevtic jovaneeeee

  • @omrimaher2754
    @omrimaher2754 Před 2 lety

    Really amazing explanation!

  • @edisvelicanin8854
    @edisvelicanin8854 Před 4 lety

    exactly what i was looking for

  • @mamusthafa6
    @mamusthafa6 Před 2 lety

    YOu are amazing... Really simplified complex things

  • @fullstackgreekdeveloper8033

    Thank you for this video!

  • @nirmesh44
    @nirmesh44 Před 4 lety

    Perfect. Very nicely done

  • @shuvokhan2054
    @shuvokhan2054 Před 4 lety +5

    You're my boss ❤

  • @BenOdari
    @BenOdari Před 2 lety

    You have helped me alot In React js

  • @nitindaphale2008
    @nitindaphale2008 Před 2 lety

    Very good explained , Love from India.

  • @benjamincisneros797
    @benjamincisneros797 Před 4 lety +3

    Great video. I just think one small refactor is to use the canViewProject function inside your filter for scopedProjects

  • @HurikaneTv
    @HurikaneTv Před 2 lety

    Kyle ... One Word: Genius

  • @pedro_jaber9357
    @pedro_jaber9357 Před 9 měsíci

    OMG! thank you. I believe in Web Dev Simplified supremacy!!!!!

  • @macarenamolina8875
    @macarenamolina8875 Před 3 lety

    THANK YOUUUUUUUUUUU!!!!!! I finally understand this.

  • @indigosay
    @indigosay Před 4 lety

    I was just about to look for this information

  • @mayank_singh_43
    @mayank_singh_43 Před 2 lety

    This is what i want , u are awesome sir 🤘🤘🤘

  • @agasthya3693
    @agasthya3693 Před 4 lety

    Hey Kayle please do video on Gulp, Grunt, webpack and parcel & when to choose which tool

  • @ononaokisama
    @ononaokisama Před 2 lety

    Literally god tier content

  • @vinhubcompters
    @vinhubcompters Před 2 lety

    best teacher ever

  • @alex_lomov
    @alex_lomov Před 3 lety

    Great layout of material.

  • @amitshrestha898
    @amitshrestha898 Před 3 lety

    Found what I am looking for thanks.

  • @iurii7752
    @iurii7752 Před 4 lety

    The best educational videos

  • @ayoubalem865
    @ayoubalem865 Před 4 lety +20

    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 !

  • @dpolo567
    @dpolo567 Před rokem +1

    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?

  • @harleyspeedthrust4013
    @harleyspeedthrust4013 Před 2 lety +1

    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

  • @talha-cs
    @talha-cs Před 2 lety

    Nicely explained

  • @sabuein
    @sabuein Před rokem

    Thank you, Kyle.

  • @tough_year
    @tough_year Před 4 lety

    Awesome video !!!

  • @jacob.lee380
    @jacob.lee380 Před 2 lety

    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

  • @houssemkhi5036
    @houssemkhi5036 Před 3 lety

    great as usual

  • @sakshamsrivastava6280
    @sakshamsrivastava6280 Před 3 lety

    thanks for this man

  • @vidumini23
    @vidumini23 Před 4 lety

    Very useful. Thank you..

  • @jodufan8754
    @jodufan8754 Před 2 lety +5

    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 Před 2 lety

      Why ? explain briefly please..

    • @jodu
      @jodu Před 2 lety

      @@montasirmahmud3585 Then you can just use bit calculations to check if a role is hierarchically over another role or not by for example using >=

  • @piyushpatil6874
    @piyushpatil6874 Před 2 lety

    Loved it :)

  • @maplestoryinchinese
    @maplestoryinchinese Před 4 lety +2

    More tutorials please!

  • @ankitdubey9310
    @ankitdubey9310 Před 3 lety

    best video, way to go

  • @rishabsharma5307
    @rishabsharma5307 Před 3 lety +1

    Awesome video

  • @joylearn2868
    @joylearn2868 Před 4 lety

    Kyle!!!
    I want to store a string like '' string'' in a variable, which each character store in a variable or array, which come from an input

  • @FSaidArslan
    @FSaidArslan Před rokem +1

    Very good ❤

  • @sonamuhialdeen7866
    @sonamuhialdeen7866 Před 3 lety

    So good tutorial

  • @bodolawale5448
    @bodolawale5448 Před 2 lety

    Lovved it thanks

  • @syedovaiss
    @syedovaiss Před 4 lety

    Hi. Can you give me an idea how to apply this logic
    User submitted a form if admin approved that user's form it will be shown otherwise not

  • @inayatcassambai469
    @inayatcassambai469 Před 4 lety

    Hey Kyle, what if we need to do a slightly different style of authentication. Say for example, you've built an accounting app where you can create/manage invoices & payments etc.. and you want to invite someone else to have access to your account. How would we make this work?

  • @matiasmanevi1521
    @matiasmanevi1521 Před 4 lety

    How would you share the permissions logic between the node backend and a ... lets say, react frontend?

  • @Millonerium
    @Millonerium Před rokem

    great video bro, please do a MERN project like this with frontend

  • @healdesk5649
    @healdesk5649 Před 3 lety +1

    it's so great thanks a lot man !!! i wonder if you made a frontend part using React/Redux it will be helpful !! :D

    • @utkarsh_108
      @utkarsh_108 Před 2 lety

      actually, login logout page usually in public folder so its is preferred to be made using HTML & CSS only

  • @tharhtetkyaw7528
    @tharhtetkyaw7528 Před 4 lety

    thanks you are a legend

  • @h4kster182
    @h4kster182 Před 4 lety

    Nice explanation

  • @hiteshrane0609
    @hiteshrane0609 Před 3 lety

    I like your teaching style and I got correct concept from you when I search. can you upload videos with hindi dubbing? is it possible.

  • @hindbensafi4646
    @hindbensafi4646 Před 2 lety

    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 ?

  • @alexandre3932
    @alexandre3932 Před 4 lety

    Good tutorial, why sometimes did you use es6 and sometimes not ?

  • @indigosay
    @indigosay Před 4 lety

    I added this video to my Gold Collection

  • @swapnilkuwar7040
    @swapnilkuwar7040 Před 3 lety

    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.