React Protected Routes | Role-Based Authorization | React Router v6

Поделиться
HTML-код
  • Опубликовано: 24 авг 2024

Комментарии • 545

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 года назад +44

    You have an app where users login and authenticate with a server, but is that all? What if there are different levels of authorization based on assigned user roles? In this tutorial you will learn how to React Router v6 to set up role-based user authorization for different parts of your React application. This tutorial uses a Node JS backend that was created in my Node JS for Beginners full course found here: ruclips.net/video/f2EqECiTBL8/видео.html - If you're just starting out with React, I suggest learning the basics first in my React JS for Beginners full course here: ruclips.net/video/RVFAyFWO4go/видео.html

    • @akshayc3314
      @akshayc3314 2 года назад

      Hi Dave,
      What if user is at home page and uses brower back button.
      Will he get navigate to login page or will remain at home page?

    • @ambrosearuwa9458
      @ambrosearuwa9458 Год назад +1

      @Dave Gray
      You are one the best teachers out there, I love the way you use stories to explain from both a client, user or developer point of view

    • @TeamBerserker032
      @TeamBerserker032 Год назад

      "src/context/AuthProvider.js
      Line 5:32: 'children' is missing in props validation react/prop-types"
      I am getting this error. Can someone please help me to resolve this

    • @bhavyajain638
      @bhavyajain638 5 месяцев назад

      I am encountering a problem...
      Using protected routes, if the user is not logged in, I redirect to login page.
      But now google has marked my login page as canonical to the order page, because google crawler is not logged in. Any way to sole this issue?
      Thank you. It is an amazing tutorial.

    • @bhavyajain638
      @bhavyajain638 5 месяцев назад

      I am encountering a problem...
      Using protected routes, if the user is not logged in, I redirect to login page.
      But now google has marked my login page as canonical to the order page, because google crawler is not logged in. Any way to solve this issue?
      Thank you. It is an amazing tutorial.

  • @klhmia
    @klhmia 2 года назад +70

    This is EXACTLY what I've been looking for over the past year. I've been stitching most of this together on my own over that time since I started my web dev journey but there was a main issue I had with JWTs and best practice for storing those (AT & RT) - you've cleared it up and then some! Thank you so much. Liked, subbed, belled - you seem like you know what we need to see. There are too many 'guides' and 'courses' that skip over the most important parts often pertaining to best practices such as storing JWT in localstorage for simplicity or because they assume you don't care about security. Very nice to have all in one best practice / security.

  • @ntjnh
    @ntjnh 2 года назад +22

    What a detailed and explanatory video about role wise routes. It feels like an personal tutor who sits besides & guides through the path. Hats Off for your efforts. Blessings. 👍

  • @maxwellshick7798
    @maxwellshick7798 2 года назад +10

    Your RUclips channel is so valuable its insane, you don't cut a single corner in your demos. I've been studying for almost a year and feel like this series has been the icing on the cake for my job hunt right now

  • @D4arkl0rd
    @D4arkl0rd Год назад +3

    I so wish that I had found this course 6 months back. Absolute gem!

  • @simonedwards7101
    @simonedwards7101 2 года назад +11

    Dave, I must say I like the style and pace of the videos. I find it really useful when you explain why we should use something unlike some other creators that say just use this.

  • @brucelee7782
    @brucelee7782 4 месяца назад +1

    great video for refreshing my memory before applying for a job

  • @SachinYadav-eh7vg
    @SachinYadav-eh7vg 2 года назад +6

    Thanks Dave for these intermediate lectures. On RUclips it's either beginners or too advanced good to see someone teaching intermediate stuff 👍

  • @TheLucidWay
    @TheLucidWay 2 года назад +2

    Dude, I feel a little more confident in my understanding after each of your tutorials. You rock.

  • @dilrukshiperera-yo5br
    @dilrukshiperera-yo5br Месяц назад

    I have followed three videos of this course, as of now. And they all were helpful.

  • @aruchgupta
    @aruchgupta Год назад +1

    Sold in less than 30 minutes! Thank you for explaining these concepts with real life scenarios.

  • @hanesmitter1469
    @hanesmitter1469 2 года назад +2

    I've been struggling with these access control in react
    You have also taught me how to add the layout of a page like a "millionaire", I was doing it the dumb way

  • @smeuj
    @smeuj Год назад +2

    Hi Dave, thank you very much for this awesome tutorial series, it helped me a lot. Could you please tell me how to keep context from "clearing" when opening link in a new tab. When i use it seems that the context is lost and auth becomes empty in RequireAuth so it redirects me to the login page. Any help would be much appreciated. Thank you

  • @anmolarora5630
    @anmolarora5630 Год назад +1

    You are not only a great help, but also an awesome awesome teacher. Thank you Dave Sir for your work, we appreciate you a ton

  • @karthikts1634
    @karthikts1634 Год назад +2

    This is by far the best tutorial I seen on the internet regarding the login/authorization related stuff of react. You never skipped a single piece of code which other youtuber normally do. The way you explain the things is really awesome and this helps me substantially in my job search.Thanks Dave for this great content🙂

  • @caffeinated-pixels
    @caffeinated-pixels 2 года назад +1

    Thanks Dave, this tutorial helped me set up some simple protected routes for an app I'm working on. Your other React Router videos have been useful as well!

  • @ayushdedhia25
    @ayushdedhia25 2 года назад +6

    Hello sir, your teaching pace and the way of teaching is just awesome 🔥❤️ its much easy to understand even a complex topics 💯💯

  • @mauroconsolani2576
    @mauroconsolani2576 2 года назад +2

    Hi Dave!
    1st of all: Thanks infinitely for your work, your constant contributions to the community and your magnificent skills to teach and share your knowledge and experience.
    2nd: I had written a long message to see if you could give me some perspective to sort out an issue I run into when implementing RequireAuth component and I figured out the issue when writing it down to explain it to you just now. You might not know, but you just helped me (again, eheh)!
    Thanks Dave!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +1

      Glad to hear that! What you did is kind of like the "rubber duck" theory where programmers explain the issue to something on their desk which helps the thought process. Teaching helps me do the same thing! 💯

    • @mauroconsolani2576
      @mauroconsolani2576 2 года назад

      @@DaveGrayTeachesCode definitely the "rubber duck" method! Thanks again!

    • @sum41greekfun
      @sum41greekfun Год назад

      @@mauroconsolani2576 If that issue is about the auth context variable loosing its value between refreshing the page I would kinda beg you for the solution :P

    • @mauroconsolani2576
      @mauroconsolani2576 Год назад

      @@sum41greekfun Hi!! I've been trying to track down my code but couldn't locate if my issue was with the context variable. If I had to guess, on refresh you should check if you have a JWT token stored in your cookies. If so, send a request to you backend with the data you need to fill your auth context variable and recover the "state" of the app.

  • @kirillzlobin7135
    @kirillzlobin7135 Год назад +1

    The playlist on how to use Chrome Dev Tools would be awesome. Please, consider to do it someday...

  • @nirmalhasposted
    @nirmalhasposted 6 месяцев назад

    You have explained the concepts to the core. This video has really helped me to understand those
    . Thank you Really helpful..

  • @mohammedhuzaifa8654
    @mohammedhuzaifa8654 Год назад

    The best guide for react ever. The attention to detail is just awesome. Thanks Dave

  • @kirillzlobin7135
    @kirillzlobin7135 Год назад

    Great and clear explanation without filler words. Amazing

  • @JokeAdeyanju
    @JokeAdeyanju 10 месяцев назад

    Dave gray made me who i am today. Blessings ❤.

  • @faris.abuali
    @faris.abuali 2 года назад +2

    Thank you so much, Mr. Dave.
    I love your videos and your way of teaching 🧡
    Great tutorials! concise and informative 👏🏻

  • @feyisayoamujoyegbe4238
    @feyisayoamujoyegbe4238 10 месяцев назад

    Just so you know youre a life saver. Your tutorial videos are always on point and helps me sort out most of the things I need to know. Keep doing what you do🤟🤟🔥🔥

  • @gilbertnyantakyi3950
    @gilbertnyantakyi3950 Год назад

    Just one tutorial from you and i am loving it. SUBSCRIBED.

  • @praveengopu9325
    @praveengopu9325 2 года назад

    ive been woking on react authentication with react router.really your worked well helped fror me thanks..now i got the motivation.i will do it

  • @Getfit-us
    @Getfit-us 2 года назад

    you have some great material! I also love the little details you add in while you are going through the code. keep it up!

  • @shubhamnagota
    @shubhamnagota Год назад

    the best detailed explanalation of RR6 and Role based control.

  • @juandaniel6726
    @juandaniel6726 2 года назад

    You can't imagine how much I appreciate this great tutorial. Thank you Sir for sharing your knowledge.

  • @onigbindedavid6630
    @onigbindedavid6630 Месяц назад

    U made me understand jwt totally 🎉❤❤❤

  • @-massimami-
    @-massimami- Год назад

    Thank you Dave, these guides are awesome and have helped me a lot 😊

  • @ramziosta
    @ramziosta 2 года назад

    perfect timing, as I am going through the same concept and setting up a Bank App!

  • @BilalTufail-nw9gs
    @BilalTufail-nw9gs Год назад

    Hi Dave,
    It's a wonderfully explained lecture about routes so far I have seen. Really appericiate your efforts and the way you are teaching beginners. Thank you so much as this really helped me in my project.

  • @shawn.builds
    @shawn.builds 2 года назад

    Another banger. I'm going one by one through this series and this one was great too!

  • @iwilliamsi
    @iwilliamsi 2 года назад

    Hi Dave. I'm thankful for this tutorial. I learned tons from it and hope you keep on making these kinda videos! God bless you!

  • @hamidabdolrahimi4606
    @hamidabdolrahimi4606 Год назад

    Thank you man. Awesome, best tutorial ever. Keep it up

  • @fernandocoluchi5013
    @fernandocoluchi5013 2 года назад

    I discovered my new favourite channel

  • @lucasbertoldo5062
    @lucasbertoldo5062 Год назад

    Thank you very much! This is exactly what I've been looking for.

  • @realarslan33
    @realarslan33 Год назад

    Best video ever on authorization

  • @allanbr.8308
    @allanbr.8308 Год назад

    Thank you, Dave. Very useful and well structured course

  • @kamrandvr4045
    @kamrandvr4045 Год назад

    Thank you, Dave. Very useful.

  • @dilrukshiperera-yo5br
    @dilrukshiperera-yo5br Месяц назад

    thanks for the advice.

  • @WTFAnyNameWorks
    @WTFAnyNameWorks Год назад

    Man, this was AWESOME! Thank you very much ❤️❤️

  • @tallitvak5325
    @tallitvak5325 Год назад

    Thanks for the last tip!

  • @legenuspl4906
    @legenuspl4906 2 года назад

    great content, you teach like Tim Buchalka from Australia :) keep up nice work and thank you

  • @ibrahimacanada
    @ibrahimacanada 2 года назад

    Very good Lesson and clear Many thanks Dave !

  • @90kidsgamezone76
    @90kidsgamezone76 Год назад

    thank you dave need more react video

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Год назад

      Currently, 55 React videos in my playlist: ruclips.net/p/PL0Zuz27SZ-6PrE9srvEn8nbhOOyxnWXfp

  • @bojjabheemaraju387
    @bojjabheemaraju387 2 года назад

    Thanks Dave. This video cleared all my doubts. 😊

  • @okeydonkey19
    @okeydonkey19 2 года назад

    you saved my life!! I love your tutorial!!!! Can't be better :D

  • @MASTERRAGE
    @MASTERRAGE 2 года назад

    Great as always, please keep on uploading, I love your content !

  • @khandoor7228
    @khandoor7228 Год назад

    Awesome just what I was looking for

  • @vnm_8945
    @vnm_8945 2 года назад

    exactly what I need it, thank you very much!

  • @abdulwahab7555
    @abdulwahab7555 Год назад

    Awesome stuff Dave!

  • @caducoder
    @caducoder 2 года назад

    Thanks a lot Dave! You helped me a lot!

  • @jonathanhammond5563
    @jonathanhammond5563 3 месяца назад

    Hi Dave, I have a question.
    You specified separating concerns between routing and authorization, but what about navigation links that utilize rrd's Link component?
    I was thinking of conditionally rendering navigation Links based on the user's role. I wasn't sure if this was still against the convention you speak of. I would hope not, but wanted to see!

  • @pinakadhara7650
    @pinakadhara7650 2 года назад

    Great video! A HOC like withRole() which handles all the authorisation logic would be handy.

  • @imkir4n
    @imkir4n 2 года назад

    Thanks Dave...learned some new things ❤️

  • @sejanas
    @sejanas 2 года назад

    Very detailed and informative content. Thank You

  • @pmioduszewski
    @pmioduszewski 2 года назад

    This channel is GOLD

  • @brendenferkans6846
    @brendenferkans6846 2 года назад +1

    I absolutely love your tutorials! They are so insightful and correctly paced. The only thing I was wondering is if you could do this same website without axios? Or is that not a good idea? I am currently building a react app for my capstone project in college, and I am not using axios.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +2

      You can just use fetch. It doesn't have all of the nice features built-in that axios does though. Axios is a lightweight dependency that will not bog down your project. Given the choice, I would use axios.

  • @Victor-wh9bs
    @Victor-wh9bs Год назад

    This video helps me a lot. ThankU so much.

  • @pratikmadekar5728
    @pratikmadekar5728 Год назад

    Thanks Dave for you valuable knowledge sharing it' very helpful to me

  • @digitalmarketingtutor
    @digitalmarketingtutor 2 года назад

    Hi, I want to say a very big THANK YOU for this video and your channel.

  • @asdasd-jg1re
    @asdasd-jg1re Год назад +1

    Somehow my auth would not change update after setAuth is called. However, it updates if I browse through my app 1~2 times.
    After hours of searching on google, I solved this with useEffect, put useNavigate inside there and made auth as dependency. So when auth is updated by setAuth, useEffect navigated the user.
    It works perfectly fine now but I wonder why yours worked. I went to your source code and copied the code almost exactly but it did not work as intended.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Год назад

      The "almost exactly" might be it - hard to compare if not exact. React Router has had some updates. Check my source package.json to see if you were using the same version or maybe an update is the difference.

  • @TurboBet_
    @TurboBet_ 5 месяцев назад

    You are the GOAT!

  • @medAmineRg
    @medAmineRg 2 года назад

    thanks dave for that great tutorial

  • @MohamedElnagar-dz8ub
    @MohamedElnagar-dz8ub 5 месяцев назад

    Thanks a lot 🥰

  • @rockfox5
    @rockfox5 2 года назад +1

    Excellent tutorial as always, Dave. Unfortunately react router doesn’t work well with Nextjs which I built my frontend on.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +1

      Thank you! I'd like to do some work with NextJS later this year 💯

  • @njorogekamau3820
    @njorogekamau3820 6 месяцев назад

    Thanks. This helped me alot

  • @zee_axis
    @zee_axis 2 года назад

    mind blowing tutorial. Hatsoff to you. You are a Superhero for me..

  • @jafeta.7553
    @jafeta.7553 Год назад

    Loved it, thank you very much.

  • @andysimmons8730
    @andysimmons8730 Год назад

    Dave this tutorial is amazing complete your node tutorial and now doing this. JWT and authorization was daunting but your tutorials made them very easy to grasp cant wait to incorporate this into my full stack projects! do you have a discord or anything like that?

  • @johnpaulpineda2476
    @johnpaulpineda2476 2 года назад

    This is what i exactly needed. Thank you so much!

  • @szymonrojek6480
    @szymonrojek6480 2 года назад +2

    Hi Dave, I watched few times these series and learn already a lot but I have got a question - you are passing the data from the server to the context. After reloading the page I got a new state which is an empty state and thats a reason that I have to log in again through the login component. What is the best idea to keep state after the login and do not loose it when the page is reloaded ? Also in the network payload I can see the password wich has been written during the sign in the application - is any chance to hide it? To be honest I learn front end dev and I am a beginner with node but literally I just want to know more what is going on on the backend side :D Thank you so much for your tutorials. BDW do you have a slack community or discord etc? I would join to that kind of group under your mentoring :D

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +2

      Great questions! 1) If you continue in this series, there is a "Persist Login" tutorial that handles the reloading and reauthorization. You will always lose app state when you reload, but that video shows how to maintain a user login. 2) You could possibly encrypt client side, but this isn't common - if there is a major concern here about your network traffic being hacked, you should use a secure connection - say a VPN if available. Also, https is a must. ...You're welcome and yes, I just opened up a Discord community here: discord.gg/neKghyefqh

  • @agroforestryconsultancyroz3157
    @agroforestryconsultancyroz3157 2 года назад

    Im enjoying the video man. Thanks

  • @divyanshmalik5512
    @divyanshmalik5512 Год назад

    great tutorial a complete life saver👍👍

  • @dovakiin0
    @dovakiin0 2 года назад

    Thank you so much
    ive been looking on how to stop redirecting to home page every time login check for goddam so long and im so thankful to you

  • @saadarman4718
    @saadarman4718 8 месяцев назад

    Wonderful as usual.

  • @od1ez
    @od1ez 2 года назад

    Amazing stuff! Thanks!

  • @vohid_abduraxmanov
    @vohid_abduraxmanov Год назад

    nice course
    Thank you bro

  • @addictedgamerclashofclansa1251
    @addictedgamerclashofclansa1251 3 месяца назад

    Can the client not manipulate allowedRoles in components? How can we resolve those potential issues?

  • @yashwanthsrinivas
    @yashwanthsrinivas Год назад

    What a great tutorial.

  • @kolynzb
    @kolynzb 2 года назад

    THank you this is exactly what i am looking for

  • @user-dc4kw7ho9b
    @user-dc4kw7ho9b 4 месяца назад

    nice thank you

  • @violabg
    @violabg 2 месяца назад

    how would you handle auth now with RouterProvider and loaders?

  • @vampiroast
    @vampiroast Год назад

    Thanks Dave very good tutorial!! 1984 and 5150? are you a Van Halen fan? 🤘🤘

  • @MsPrakhar12
    @MsPrakhar12 Год назад

    Very informative tutorial 👏👏

  • @msalam4248
    @msalam4248 2 года назад

    Thank you so much dave....

  • @fikilekentane6982
    @fikilekentane6982 11 месяцев назад

    ...u awesome Dave. thanks so very much

  • @adila4658
    @adila4658 Год назад

    I’m a bit confused, I have a login form that connects to sql db then response is 200 if user exists. Why would I need a token if validation is already achieved? Is this a silly question?

  • @azizbekmukhtorov
    @azizbekmukhtorov 8 месяцев назад

    thank youu Dave

  • @pambisichone4592
    @pambisichone4592 Год назад

    You tutorial have helped a lot thanks for providing this content especially this series. I just wanted to ask how a can use this same role-based routing approach in my react-native application

  • @danieltkach2330
    @danieltkach2330 Год назад

    God bless you Dave.

  • @internet_glen
    @internet_glen Год назад

    5150 for the admin. dave loves halen!

  • @muhammedcansoy6131
    @muhammedcansoy6131 9 месяцев назад

    excellent thank you !

  • @ricardopellecer7670
    @ricardopellecer7670 7 месяцев назад

    Hi Dave, this is exactly what I needed! Thanks a lot!. I just noticed that if I create a user that is not authorized for certain page and I look for that page directly in the browser search bar instead of using a button like you do, I get redirected to the home page, instead of the unauthorized one. Do you know why is this happening and how could I change it?
    Once again, thanks a lot for the help!!

  • @shaantanukulkarni5668
    @shaantanukulkarni5668 6 месяцев назад

    Loved the video❤

  • @bhavyajain638
    @bhavyajain638 5 месяцев назад

    I am encountering a problem...
    Using protected routes, if the user is not logged in, I redirect to login page.
    But now google has marked my login page as canonical to the order page, because google crawler is not logged in. Any way to sole this issue?
    Thank you. It is an amazing tutorial.

  • @husseinj7505
    @husseinj7505 8 месяцев назад

    Hello Dave,
    Everything is working fine in my code but after I login and refresh the browser, it redirects me to the login page and the useAuth object is being reset.
    Can you help me please ?
    Thanks.