React Router v6 | Public and Protected Routes

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 119

  • @ArisAris-fs1ip
    @ArisAris-fs1ip ปีที่แล้ว +1

    After literaly 1 month failling to build protected Routes, using outlet and protected component from shitty tutorials, now finally with your way works! Thank you!

  • @feliprdev9762
    @feliprdev9762 2 ปีที่แล้ว +1

    wow, that was really simplified and still functional, i think that this logic will fit my project, thanks a lot 🙏

  • @clementlin3140
    @clementlin3140 2 ปีที่แล้ว +5

    This is gold!! Thanks for sharing the knowledge. Thumbs up and subscribed!

  • @engineermaxwel6732
    @engineermaxwel6732 2 ปีที่แล้ว +3

    Its time you start making videos weekly I am your fan. Very simple and well explained, we owe you Monetization as your fan

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +1

      Thanks alot. Really appreciate your support. Was pretty occupied last month. You guys really motivate me. Will bring new videos soon. Thanks for watching 🔥🔥

    • @thecareercoach231
      @thecareercoach231 2 ปีที่แล้ว +1

      Yes 😍

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +1

      Thank you ☺️

  • @TheGroovySpace
    @TheGroovySpace 2 ปีที่แล้ว +2

    The way you explain the thing is great 👍👍👍👍

  • @shivaa3ps177
    @shivaa3ps177 2 ปีที่แล้ว +1

    Hmm... You stood true to your channel name. Its definitely easy to follow what you have done.👌

  • @Ayoutubeaccount3
    @Ayoutubeaccount3 2 ปีที่แล้ว +1

    One of the few tutorials that actually helped, thanks

  • @jaym3034
    @jaym3034 2 ปีที่แล้ว +1

    Thank you. A lot! Saving the user state is what I have been looking for!

  • @fluffymaverick
    @fluffymaverick 2 ปีที่แล้ว +2

    Thank you for the effort making this tutorial. Really helpful 👍

  • @willyhorizont8672
    @willyhorizont8672 2 ปีที่แล้ว +1

    Bahut badhiya super!

  • @the_true_hier_to_the_sharingan
    @the_true_hier_to_the_sharingan 2 ปีที่แล้ว +1

    Brilliant short videos but detailed and quick just what we need

  • @ratonconcigarro8612
    @ratonconcigarro8612 2 ปีที่แล้ว +1

    This video is so usefully, thanks my friend :D

  • @蹦太君-o4d
    @蹦太君-o4d 2 ปีที่แล้ว

    wow so cool, this problem was confused me for a long time,but you explain so easy to understand!!!

  • @JohnDoe-ej6vm
    @JohnDoe-ej6vm 2 ปีที่แล้ว +1

    wonderful explanation.

  • @gillesa290
    @gillesa290 2 ปีที่แล้ว +1

    Very useful ! Thanks for sharing.

  • @baranoden
    @baranoden 2 ปีที่แล้ว +1

    You are the best and deserve more

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +1

      Thanks alot. Really appreciate your support 🔥🔥

  • @kritigoswami7382
    @kritigoswami7382 2 ปีที่แล้ว +2

    Great explanation again. 😇

  • @sujitrockstar221
    @sujitrockstar221 2 ปีที่แล้ว +1

    Helpful to all IT students.Nice video

  • @h__m7551
    @h__m7551 2 ปีที่แล้ว +1

    thank you very much!! amazing video !!!!🙂🙂

  • @slablife
    @slablife 2 ปีที่แล้ว +2

    Great job, very clear and concise. Sub'd!

  • @vloggingwithMisha
    @vloggingwithMisha 2 ปีที่แล้ว +2

    Such an amazing video ✨

  • @mohamedkalid8713
    @mohamedkalid8713 2 ปีที่แล้ว +1

    Nice Explanation bro, you make it easy 👌👌

  • @guilhermematos7448
    @guilhermematos7448 2 ปีที่แล้ว +1

    Very helpful

  • @braham.prakash
    @braham.prakash 2 ปีที่แล้ว +1

    Exactly what i wanted
    Thanks man

  • @cecibenitez3917
    @cecibenitez3917 2 ปีที่แล้ว +1

    thanks I implemented this in my hobbie project, works perfect!

  • @thecareercoach231
    @thecareercoach231 2 ปีที่แล้ว +2

    Great vdo ✨

  • @0xredpill
    @0xredpill 2 ปีที่แล้ว +1

    You are amazing, you saved me from heart attack 🥰🤞🏾😋

  • @ZexDev
    @ZexDev 2 ปีที่แล้ว +1

    bro that cool, thx fo this video

  • @garbjorn1757
    @garbjorn1757 2 ปีที่แล้ว +1

    How about user role if admin or normal user. Because if I store in local storage it can be edited. How to make secure

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      You can store it in session. And while making any api call your backend should also check if the req is coming form the expected user or not and then you can throw unauthorised error from your backend

  • @akashbose3682
    @akashbose3682 2 ปีที่แล้ว +1

    Nice to watch everything u explained ❤️

  • @asfnobambu
    @asfnobambu 2 ปีที่แล้ว +1

    Strait to the point !! Thank you :-)

  • @sayyedaamerasharali7583
    @sayyedaamerasharali7583 2 ปีที่แล้ว +1

    Thanks brother this helps me a lot. 👍

  • @rahulkrishna164
    @rahulkrishna164 2 ปีที่แล้ว +3

    Great video

  • @weslolo1074
    @weslolo1074 2 ปีที่แล้ว +1

    Thank you!!!

  • @darkness97439
    @darkness97439 2 ปีที่แล้ว +3

    it's super simple and not complicated but the problem is when i want to have a 404 page you already use the "*" so how i will create my 404 page ? :/

  • @vaibhavshetty3781
    @vaibhavshetty3781 2 ปีที่แล้ว

    Thank you so much so how can we use this for admin and user

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      You can define two roles within your state and render routes conditionally specific to your user's role

  • @clarkson9331
    @clarkson9331 2 ปีที่แล้ว +1

    Thanks, i didnt know i can wrap code using &&. i was always doing { user ? : ... ) nice

  • @techjourneyrecoded4114
    @techjourneyrecoded4114 2 ปีที่แล้ว +1

    Really well explained!!

  • @tarik9563
    @tarik9563 2 ปีที่แล้ว

    Hi, followed every step with same code but still ended up with losing localstorage after refreshing the page or when I go to the profile or dashboard page
    tried everything in my beginner power but couldn't find the issue !
    can you help me with any idea ?
    my react router dome is 6.3.0 now

    • @tarik9563
      @tarik9563 2 ปีที่แล้ว

      for whome they have the same problem as me, the solution is to call document.getElementById("root") last in the reactDom.render function and to remove reportWebVitals()

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      Can you share your code snippet?

  • @narayanbhagat510
    @narayanbhagat510 2 ปีที่แล้ว +1

    I am able to access the page like dashboard and profile using URL even after logout. how can I protect it ?

    • @raho_mania
      @raho_mania 2 ปีที่แล้ว

      when you logout you shoud remove the user entry from localstorage

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +2

      Firebase signout function does it for you. Make sure you are setting the user state to null in onAuthChanged function when no user is found

  • @gokulap5644
    @gokulap5644 2 ปีที่แล้ว +2

    While reloading a dashboard page it's redirects me to profile page. Will you help me 😊

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +2

      It reloads back to the profile page because when ever we reload we set the user in useEffect and the generic route which we have redirects us to the profile page. Instead of having the generic route with path=* outside the auth conditions we can have them separately for both the user states
      You can have a look at the code here -
      codesandbox.io/s/react-router-protected-routes-nynrfw?file=/src/App.js

    • @gokulap5644
      @gokulap5644 2 ปีที่แล้ว

      @@FullstackSimplified ya got it thanks a lot love from india ❤️

  • @profeskills768
    @profeskills768 2 ปีที่แล้ว +1

    thank you :)

  • @samnayakawadi
    @samnayakawadi 2 ปีที่แล้ว +1

    Subscribed.

  • @maxwelochieng7658
    @maxwelochieng7658 2 ปีที่แล้ว

    Probably The Best Protected Routes I have Seen. But I have a suggestion for You is something that I am struggling with. I want to create a Website with Auth but after you log in we have a dashboard that contains nav links but everytime I include Link the Browser renders an empty page or the navbar disappears but I want the Nav bar to be static . I am beginner

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      Make sure you use the Link component from react router dom and not tag.

    • @maxwelochieng7658
      @maxwelochieng7658 2 ปีที่แล้ว

      @@FullstackSimplified okay I'll get back to you

  • @TuanAnh-ll1lu
    @TuanAnh-ll1lu 2 ปีที่แล้ว +1

    thank you very much

  • @contactdi8426
    @contactdi8426 2 ปีที่แล้ว

    What's the background music? Can you please share the name. That's beautiful. And Obviously, your videos are super helpful

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      Nana Kwabena | Timpani Beat - th-cam.com/video/tycUC95voac/w-d-xo.html

  • @mihirharshe6073
    @mihirharshe6073 2 ปีที่แล้ว

    Isn't verifying through a boolean value stored in localStorage really insecure as anyone can modify it?

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      Storing the Boolean value is just for showing how things work. In real scenario you'll have a proper auth system which you can use to determine if the user is authenticated or not and accordingly render the routes

  • @danieltkach2330
    @danieltkach2330 2 ปีที่แล้ว

    Fantastic! Can you explain how to work with the token expiration, and also how to work with roles, whether the role should be saved on the token, please.

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      You can save the token in localstorage and retrieve it everytime when you app mounts and check if the token is alive.
      For roles it would be better if you fetch it everytime from your backend when the app mounts for the first time

    • @JohnDoe-ej6vm
      @JohnDoe-ej6vm 2 ปีที่แล้ว +1

      i have 3 roles , public , student , admin .
      for each i want to have different routes and sidebar .
      what should be the flow ?

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +1

      If you have three roles so instead of storing the boolean value in the logged in state., you can use object or strings as roles and render the routes accordingly

    • @JohnDoe-ej6vm
      @JohnDoe-ej6vm 2 ปีที่แล้ว

      @@FullstackSimplified
      If isAdmin or isMode do this.
      { isAdmin || isMode && something }

    • @JohnDoe-ej6vm
      @JohnDoe-ej6vm 2 ปีที่แล้ว

      I am trying to do this . Can you please tell me what's my mistake in this ?

  • @augischadiegils.5109
    @augischadiegils.5109 2 ปีที่แล้ว +1

    ❤️❤️❤️❤️❤️❤️❤️

  • @rinkugoswami5323
    @rinkugoswami5323 2 ปีที่แล้ว +2

    👍

  • @onyilimba
    @onyilimba 2 ปีที่แล้ว +1

    Nice tutorial, but why the background music though?

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      Thanks for the feedback. Will fix this in the coming videos.

  • @evoteck7273
    @evoteck7273 2 ปีที่แล้ว +1

    I got an infinite loop after doing this keeps saying I can't call a setstate inside use Effect hook

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว +1

      Please check if you have added an empty dependency array.
      useEffect(() => ....your code, [])

  • @kashmirtechtv2948
    @kashmirtechtv2948 8 หลายเดือนก่อน

    What about showing and not showing Navbar?

    • @FullstackSimplified
      @FullstackSimplified  8 หลายเดือนก่อน

      You can do the similar thing, use ternary to show/hide navbar based on auth state

  • @yotsusan_machi
    @yotsusan_machi 2 ปีที่แล้ว

    note for me operator dan akan tampil jika semuanya bernilai true

  • @adilhashmi1735
    @adilhashmi1735 2 ปีที่แล้ว

    there is a problem in this code it is navigating us to the "/profile" on reloading

    • @FullstackSimplified
      @FullstackSimplified  2 ปีที่แล้ว

      If you are storing the logged in state to 'true' in the local storage then it will load the profile page.

  • @worldclasscode1847
    @worldclasscode1847 2 ปีที่แล้ว +1

    Great video! Contact me

  • @soyayebhasanshafin8977
    @soyayebhasanshafin8977 2 ปีที่แล้ว +1

    Thank you so much