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

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 546

  • @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: ua-cam.com/video/f2EqECiTBL8/v-deo.html - If you're just starting out with React, I suggest learning the basics first in my React JS for Beginners full course here: ua-cam.com/video/RVFAyFWO4go/v-deo.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 2 роки тому +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 7 місяців тому

      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 7 місяців тому

      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 UA-cam 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

  • @noone_and_nobody
    @noone_and_nobody Рік тому +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.

  • @SachinYadav-eh7vg
    @SachinYadav-eh7vg 2 роки тому +6

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

  • @brucelee7782
    @brucelee7782 6 місяців тому +1

    great video for refreshing my memory before applying for a job

  • @HologramJay
    @HologramJay 2 роки тому +2

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

  • @dilrukshiperera-yo5br
    @dilrukshiperera-yo5br 3 місяці тому

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

  • @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🙂

  • @aruchgupta
    @aruchgupta Рік тому +1

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

  • @smeuj
    @smeuj Рік тому +3

    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

  • @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

  • @kirillzlobin7135
    @kirillzlobin7135 Рік тому +1

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

  • @nirmalhasposted
    @nirmalhasposted 8 місяців тому

    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

  • @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!

  • @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.

  • @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

  • @kirillzlobin7135
    @kirillzlobin7135 Рік тому

    Great and clear explanation without filler words. Amazing

  • @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

  • @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 💯💯

  • @jonathanhammond5563
    @jonathanhammond5563 5 місяців тому

    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!

  • @feyisayoamujoyegbe4238
    @feyisayoamujoyegbe4238 Рік тому

    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🤟🤟🔥🔥

  • @shawn.builds
    @shawn.builds 2 роки тому

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

  • @gilbertnyantakyi3950
    @gilbertnyantakyi3950 Рік тому

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

  • @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.

  • @ricardopellecer7670
    @ricardopellecer7670 9 місяців тому

    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!!

  • @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 👏🏻

  • @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!

  • @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.

  • @JokeAdeyanju
    @JokeAdeyanju Рік тому

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

  • @ramziosta
    @ramziosta 2 роки тому

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

  • @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!

  • @HonestPleb
    @HonestPleb 6 місяців тому

    Hey Dave, Great playlist btw. I just completed both NodeJS and React Auth playlists. I had a doubt lingering in my mind. Please answer that whenever you can. It seems we can access protected routes which do not require to fetch data from the backend even after the access token get expired. If so, is this something to be concerned about? Should I make it this way that I ask the backend for a new access token every time I open any protected route? or is this overkill?

  • @leonaxiel8270
    @leonaxiel8270 Рік тому

    Hello, first of all thanks for this tutorial, and I would like to know how the accesstoken data api is made up, in order to understand the backend structure well.🧐🧐

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      It's at the link in the description to my node.js course. It's the back end built in that course

  • @ThefirstAbraham
    @ThefirstAbraham 4 місяці тому

    Hi Dave,
    I want to say thank you for your tutorials. They have really been a great help to me. I do have a question about this tutorial: It seems that once the user logs in, whether the user's access token has expired or not, the user still has access to the protected routes. Is this how it is meant to be? I am aware that the user doesn't have access to the backend API though.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  4 місяці тому

      It's been a couple of years since I made this, so I would need to look again to confirm - but you can check the token expiry on the client as well if you want. My memory says you should be redirected already.

  • @mounir101
    @mounir101 Рік тому

    I find all of your React videos to be clear and easy to understand. However, I'm still confused about which one to choose to watch. Thanks anyway. Can use this project with a PHP backend? instead of Node.js

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      Yes, you can use any backend REST API you choose to build. I have a React playlist on my channel that provides the videos in the order created. You can also look in the description of this video for links to other videos about auth in React.

    • @mounir101
      @mounir101 Рік тому

      @@DaveGrayTeachesCode Thanks Dave. I'll see

  • @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.

  • @-massimami-
    @-massimami- Рік тому

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

  • @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.

  • @realarslan33
    @realarslan33 Рік тому

    Best video ever on authorization

  • @bhavyajain638
    @bhavyajain638 7 місяців тому

    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.

  • @user_noway
    @user_noway Рік тому

    Hello, I'm newbie, just a question, i just want to make a page for the owner of the website and customer shouldn't access that page, even if they try to write the in address bar and it re-directs them to website. how is that possible? is it done the way u explained and showed in the video?

  • @hamidabdolrahimi4606
    @hamidabdolrahimi4606 Рік тому

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

  • @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?

  • @lucasbertoldo5062
    @lucasbertoldo5062 2 роки тому

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

  • @slatanek
    @slatanek 2 роки тому

    Great tutorial. My only gripe is nobody uses JS for any serious work (if they do, they should stop). Why no TS if especially for commercial use JS is just a no-no?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Thank you! And I understand the TS request. I think about beginners or those just beyond beginners level first as I teach new students at university every year. I will provide Typescript content on my channel in the near future, but I will always introduce concepts first without it which lowers the entry level.

  • @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?

  • @georgy2763
    @georgy2763 2 роки тому

    Dear Dave, can you pls elaborate on why and how this line of code works. Const form = location?.state?.from?.pathname || “/“ my main concern is state.from part. I didn’t find an example of this even in the official doc. Why we didn’t use just location.pathname? Also, initially the state property is empty, but during my tests, the value of it seems always to be “/“. In what cases it will be different? In any case, it would be interesting to know more about the location object. Thanks)

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Good question and so far the React Router v6 docs do not provide much on this. However, they do give a nice code example here: reactrouter.com/docs/en/v6/examples/auth ..After you read the info on that page, click their code example to launch it. You will see their LoginPage component uses this which is where I referenced it from.

  • @danieltkach2330
    @danieltkach2330 2 роки тому

    In V6 there's a simplified way of doing it with nested routes, would you do a new tutorial please? I found some cool blogs that explain it, but nothing like your examples! Much appreciated.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      This tutorial uses React Router v6 and covers nested routes. These are protected routes which are nested inside of a RequireAuth component which receives the user roles. If you are just looking for nesting without authentication or roles, you can also see that with the use of Outlet inside the layout component. Outlet represents the child components: reactrouter.com/docs/en/v6/components/outlet ..If you are looking for a different React Router v6 tutorial with nesting, I recommend my intro to React Router v6 here: ua-cam.com/video/XBRLVRjZ3CQ/v-deo.html

    • @danieltkach2330
      @danieltkach2330 2 роки тому

      @@DaveGrayTeachesCode thank you for replying Dave, you must be one of the very few teachers here who replies, I can't thank you enough. This stuff is complicated at times and a little reply like that makes a HUGE difference for someone learning this stuff. You are right, you do have the nested routes example I was looking for, but then you removed it in the final version, correct? Since you apply "RequireAuth" individually to each route, that's what confused me, why did you change that? I will have to watch this a couple of times.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      @@danieltkach2330 you're welcome. I changed it for the role specific routes. 💯

  • @pambisichone4592
    @pambisichone4592 2 роки тому

    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

  • @husseinj7505
    @husseinj7505 10 місяців тому

    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.

  • @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

  • @andresbreuer
    @andresbreuer 2 роки тому

    Hi Dave!! This Regiter/Login playlist is AWESOME! I just wanted to know if the role codes you are using (2001, 1984, 5150) are standards or just invented by you. Thanks!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +2

      Just invented by me. Any company may have their own codes. 1984 and 5150 are Van Halen albums! 🎸🤘

    • @andresbreuer
      @andresbreuer 2 роки тому

      @@DaveGrayTeachesCode Nice!!

  • @vadirajkanakagiri3410
    @vadirajkanakagiri3410 Рік тому

    Hi Dave. This is just amazing. Next level detailing. I had one doubt regarding React router dom that, whenever I enter url manually, it gets redirected to the home page. What changes do I need to make inorder for me to get the correct components to be redered even by manually entering the URL and not only from the clicks to the navlinks

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      Entering a URL manually reloads the app. That is just how React Router and overall, React, works. They are single page apps pretending to be multi-page. If you keep going in this series (links in description), you will see how I handle this in the Persist Login tutorial.

  • @allanbr.8308
    @allanbr.8308 Рік тому

    Thank you, Dave. Very useful and well structured course

  • @Photoficaj
    @Photoficaj 10 місяців тому

    Hi Dave, your video is amazing, but i have ad doubt, i am creating an app which has front end with react and backend on express with apis, now , for authorization of the API i have JWT implemented correctly with passport jwt, but how can i implement stateful session with passport local strategy for the front end? i am very blurry there.
    Example: when the JWT expires the API requests are unauthorised, but the application doesn't logs the user out as JWT is stateless, therefore the use can still access the protected routes with no data(as the data is fetched from the API).
    Can you help?

  • @gamingwithmash4261
    @gamingwithmash4261 6 місяців тому

    I'm new to authorization. Can you tell me if I can create authorization easily using react router or JWT tokens are better? BTW I'm using firebase for authentication, for backend expressJS and MongoDB

  • @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 💯

  • @andrewvaldez71
    @andrewvaldez71 2 роки тому

    Learned a lot from this! Unfortunately across each route my auth state seems to get reset back to {}. Will look into it further and report back if I find anything

    • @andrewvaldez71
      @andrewvaldez71 2 роки тому

      Found this is a feature not a bug. I’ll need to use localstorage

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      @@andrewvaldez71 keep going in this series. About two more videos and you will reach the persistent login video. I recommend avoiding local storage for auth data.

  • @sin4659
    @sin4659 5 місяців тому

    @DaveGrayTeachesCode im not seeing this issue anywhere, feels like im the only one with it? it says setAuth is not a function? everything is set up the same i have no idea why this error is popping, doesn't seem to make anysense. it pops on the login handleSubmit function...any fixes for this?

  • @pinakadhara7650
    @pinakadhara7650 2 роки тому

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

  • @markoseovac3185
    @markoseovac3185 Рік тому

    when i'm in admin panel index page that is allowed only to admin role and go to another protected route under admin protection and refresh the page it sends me back to admin index page...how to solve that?

  • @MaHyxa
    @MaHyxa 4 місяці тому

    I cant understand what am i doing wrong. I did everything step by step, i'm able to setAuth in AuthProvider through Login page, but once i reload page all values are gone. RequireAuth always getting auth empty. How does it store values in your case? I cant find any line of code about storage of auth values. From where RequireAuth is getting auth values if it's gone after navigating from Login page?

    • @UrBrothaInChrist
      @UrBrothaInChrist 4 місяці тому

      Got the same problem and it only worked when i stored them in the localstorage

  • @WTFAnyNameWorks
    @WTFAnyNameWorks Рік тому

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

  • @loganrossignol
    @loganrossignol Рік тому

    Not sure if this was discussed, but the auth loses its value when the page is reloaded, causing the user to effectively log out. Any solution to that? I think I have an idea, but wasn't sure if one existed already

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      Link in the description to the Persist Login video in this series.

  • @legenuspl4906
    @legenuspl4906 2 роки тому

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

  • @vampiroast
    @vampiroast 2 роки тому

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

  • @dharunr2002
    @dharunr2002 Рік тому

    even if we logged in still we can access the login page using the url. Is that correct we still able to access the login page even after logged in?

  • @dimitrispapakos4020
    @dimitrispapakos4020 9 місяців тому

    Hello your code is perfect. I would like some assistance please I am using only password to authenticate instead of username, how do we modify the code in this case please? (We are pulling our code from json files). Thanks

  • @addictedgamerclashofclansa1251
    @addictedgamerclashofclansa1251 5 місяців тому

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

  • @bohanwu9956
    @bohanwu9956 2 роки тому

    Hi Dave! Thanks so much for your tutorial. I have a question. How did you pre-set those users with certain roles? In other words, the user I sign up is just a user not editor nor admin. How do I create an editor or an admin?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +2

      I didn't build an admin panel into the backend for this example, so instead, you could just edit the user data in MongoDB to add the desired roles. I should add an admin panel tutorial to show how to make changes to users. Good idea! 💯

  • @kamrandvr4045
    @kamrandvr4045 Рік тому

    Thank you, Dave. Very useful.

  • @bains273
    @bains273 Рік тому

    HELP!!!!in registration from. ui there are no fields to set roles,how are the diferent roles set ???

  • @timmanchester4515
    @timmanchester4515 2 роки тому +1

    I really liked your video. I've started on the series, thanks. I am having a weird issue though. After I login if I navigate to any other page and look at a break point in the RequireAuth component, the context value gets reset to an empty object and I can't access any protected pages. The only setAuth call is in Login. Do you have any tips as to what I should look for to figure out why this is happening?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Thank you, Tim. My best suggestion is to download my source code (available at resources link in description) and compare to yours for differences.

    • @crowlks6222
      @crowlks6222 2 роки тому

      Hi, I seem to have the same problem, did you manage to solve it?

  • @abvenant3394
    @abvenant3394 Рік тому

    Hi Dave, Thank you for the beautiful tutorial as always. what if I want the user to be sent to the pages they have the right to see and hide the pages they don't have access to. If you are an editor you will only see editors-allowed pages(different navigation menus for other users)?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      You're welcome! You can structure your pages and specify which roles are allowed to see them in anyway you want. This is just one example but the structure is up to you.

  • @violabg
    @violabg 4 місяці тому

    how would you handle auth now with RouterProvider and loaders?

  • @jitujazz123
    @jitujazz123 2 роки тому

    Thanks for this tutorial Dave. I had a question, how would I approach setting field level permissions instead of just page/screen level? For example, on a particular page I have 5 textboxes and some roles can edit some and some cannot edit any. How would I approach a solution for this?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Great question! This is something I am doing in my upcoming MERN series, too. You need to evaluate the role(s) and conditionally show or enabled the inputs or buttons based on those roles. Pseudo-logic here, but basically: if (isAdmin) enable

  • @vitaliibudkin8210
    @vitaliibudkin8210 Рік тому

    Hi, Dave! Thanks for the video! Few questions: Is it safe to store user role in a Redux store? User can change it via Redux dev tools. Can we hide some admin menu items in the app for non-admin users?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      You're welcome! You can do anything you want in your app so no worries on putting in admin options for users to change their own settings. Yes, you can store user roles in Redux and disable Redux devtools in your deployment. I show how to do that here: ua-cam.com/video/3QaFEu-KkR8/v-deo.html

    • @vitaliibudkin8210
      @vitaliibudkin8210 Рік тому

      @@DaveGrayTeachesCode Thank you, that's great additional moments!

  • @MrOwenjames24
    @MrOwenjames24 Рік тому

    Thanks Dave this is a great tutorial. I'm using the same route structure as you - one issue I'm having is that when I refresh it takes the user back to the login page, when I don't want this to happen as they have an access token. Any help on what I might be doing wrong/how to overcome this issue is appreciated :)

    • @MrOwenjames24
      @MrOwenjames24 Рік тому

      I just did a quick console.log of auth after refreshing and it's an empty object so I guess it makes sense for it to return to the login screen. But how do I overcome this?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      Yes, state is reset in any React app when you refresh. It's reloading the app. Keep going in this playlist (link in description). Another tutorial covers the Persistent Login strategy.

  • @fernandocoluchi5013
    @fernandocoluchi5013 2 роки тому

    I discovered my new favourite channel

  • @sheldonfourie5959
    @sheldonfourie5959 Рік тому

    So I get that someone can dig in to see roles but can they also modify their own roles? How would we create new users with roles is this done through a rest client mainly?

  • @ayushgogna9732
    @ayushgogna9732 Рік тому

    This video helped me alot thanks and i wanted to ask do you plan on doing a video on nextjs 13 app dir with role based auth and refresh token?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      I have a full course on Next.js with the app router. I will be covering auth in Next.js soon.

    • @ayushgogna9732
      @ayushgogna9732 Рік тому

      @@DaveGrayTeachesCode amazing cant wait

  • @okeydonkey19
    @okeydonkey19 2 роки тому

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

  • @nhatanhng03
    @nhatanhng03 4 місяці тому

    hello sir, can you provide ur backend code please? I just wanna know ur backend need to specify anything related to token or authentication , etc. or just a normal backend to add account and login.

  • @onigbindedavid6630
    @onigbindedavid6630 3 місяці тому

    U made me understand jwt totally 🎉❤❤❤

  • @MASTERRAGE
    @MASTERRAGE 2 роки тому

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

  • @johnsanthosh9540
    @johnsanthosh9540 Рік тому

    I cant find the starter code in the repo .. I can find only the completed project

  • @cruquen
    @cruquen 2 роки тому

    Hi Dave. Is there a video where you have written context/AuthProvider used in this video? Thank you

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Yes, the links to all the videos in this series should be in the description.

  • @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

  • @Aditya-zl4qz
    @Aditya-zl4qz 2 роки тому

    Hi Dave, Could you please create a course on react with typescript.

  • @henrynanabeyinagyapong1548
    @henrynanabeyinagyapong1548 Рік тому

    Do you have a Playlist for React Js upto this video?

  • @yomamasofat413
    @yomamasofat413 Місяць тому

    7:40 whats the purpose of using the Layout and Outlet component?

  • @koribrus
    @koribrus Рік тому

    Excellent, thank you David.
    One question. Is there any factor that would cause a delay in accessing the return value for the useAuth() hook?
    I have a problem where one particular route inside the list of RequireAuth routes is rendering without gaining access to the useAuth() object (ie when I console.log the return value of the useAuth() hook it reads null when rendered. As a result I get a redirect away from the page and can't view the desired content.
    This only happens on one component. I've set up that component the same as the other pages. Any ideas?
    I can also confirm its not limited to your protected routes solution. I had this same problem with my previous approach.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      Really impossible for me to guess about your code & project. That said, if it works for you everywhere else, there must be something about the way you are implementing the one area that it is not working in. It's not the hook if you have it working elsewhere, but something about the structure or what you are trying to do.

  • @parinyasuwanitch5057
    @parinyasuwanitch5057 2 роки тому

    Hi Dave Thank u so much for a wonderful tutorial. Helps me a lot. I am new to React and May I ask here, right after user logged in but user can still access log in page. How can we redirect user back to Home every time they try to access log in page? Thank you very much

  • @bojjabheemaraju387
    @bojjabheemaraju387 2 роки тому

    Thanks Dave. This video cleared all my doubts. 😊

  • @pliniojr95
    @pliniojr95 Рік тому

    I'm wondering if there could be a way to hide the user codes to prevent someone from getting a hold of them, because even if we don't specify what each code means, it's not gonna take too long for someone to figure out what they mean and then change the code and give a user access to a page it shouldn't have in the first place. The first thing that came to my mind was using the .env, but i'm not sure if it works.

    • @izzy7541
      @izzy7541 Рік тому +1

      I don't think the list of icons for the roles is a secret. The user role comes from the server anyway and is simply checked. And if a user can access a protected page, he will just get a broken application