React Router v6 | Public and Protected Routes

  Рет қаралды 33,198

Fullstack Simplified

Fullstack Simplified

Күн бұрын

Пікірлер: 119
@ArisAris-fs1ip
@ArisAris-fs1ip Жыл бұрын
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!
@FullstackSimplified
@FullstackSimplified Жыл бұрын
Glad it helped. Thanks for watching
@clementlin3140
@clementlin3140 2 жыл бұрын
This is gold!! Thanks for sharing the knowledge. Thumbs up and subscribed!
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thankyou for subscribing..
@gokulap5644
@gokulap5644 2 жыл бұрын
While reloading a dashboard page it's redirects me to profile page. Will you help me 😊
@FullstackSimplified
@FullstackSimplified 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 ❤️
@garbjorn1757
@garbjorn1757 2 жыл бұрын
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
@engineermaxwel6732
@engineermaxwel6732 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 3 жыл бұрын
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 3 жыл бұрын
Yes 😍
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you ☺️
@Ayoutubeaccount3
@Ayoutubeaccount3 2 жыл бұрын
One of the few tutorials that actually helped, thanks
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped. Thanks for watching
@shivaa3ps177
@shivaa3ps177 2 жыл бұрын
Hmm... You stood true to your channel name. Its definitely easy to follow what you have done.👌
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad you liked it. Thanks for watching 🔥
@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
@feliprdev9762
@feliprdev9762 2 жыл бұрын
wow, that was really simplified and still functional, i think that this logic will fit my project, thanks a lot 🙏
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad you liked it. Thanks for watching
@darkness97439
@darkness97439 2 жыл бұрын
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 ? :/
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
You can do something like this
@TheGroovySpace
@TheGroovySpace 3 жыл бұрын
The way you explain the thing is great 👍👍👍👍
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you
@willyhorizont8672
@willyhorizont8672 2 жыл бұрын
Bahut badhiya super!
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching
@fluffymaverick
@fluffymaverick 2 жыл бұрын
Thank you for the effort making this tutorial. Really helpful 👍
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching. Glad you liked it
@jaym3034
@jaym3034 2 жыл бұрын
Thank you. A lot! Saving the user state is what I have been looking for!
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped. Thanks for watching
@ratonconcigarro8612
@ratonconcigarro8612 2 жыл бұрын
This video is so usefully, thanks my friend :D
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching
@narayanbhagat510
@narayanbhagat510 3 жыл бұрын
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 3 жыл бұрын
when you logout you shoud remove the user entry from localstorage
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
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
@蹦太君-o4d
@蹦太君-o4d 2 жыл бұрын
wow so cool, this problem was confused me for a long time,but you explain so easy to understand!!!
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad you liked it!
@kritigoswami7382
@kritigoswami7382 3 жыл бұрын
Great explanation again. 😇
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you
@JohnDoe-ej6vm
@JohnDoe-ej6vm 2 жыл бұрын
wonderful explanation.
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped. Thanks for watching 🔥
@vloggingwithMisha
@vloggingwithMisha 3 жыл бұрын
Such an amazing video ✨
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you 🔥
@sujitrockstar221
@sujitrockstar221 3 жыл бұрын
Helpful to all IT students.Nice video
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you
@the_true_hier_to_the_sharingan
@the_true_hier_to_the_sharingan 2 жыл бұрын
Brilliant short videos but detailed and quick just what we need
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching 🔥
@gillesa290
@gillesa290 2 жыл бұрын
Very useful ! Thanks for sharing.
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped. Thanks for watching
@thecareercoach231
@thecareercoach231 3 жыл бұрын
Great vdo ✨
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thanks for watching 🔥
@h__m7551
@h__m7551 2 жыл бұрын
thank you very much!! amazing video !!!!🙂🙂
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching!!
@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?
@baranoden
@baranoden 2 жыл бұрын
You are the best and deserve more
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks alot. Really appreciate your support 🔥🔥
@slablife
@slablife 2 жыл бұрын
Great job, very clear and concise. Sub'd!
@mohamedkalid8713
@mohamedkalid8713 2 жыл бұрын
Nice Explanation bro, you make it easy 👌👌
@braham.prakash
@braham.prakash 3 жыл бұрын
Exactly what i wanted Thanks man
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thanks for watching
@sayyedaamerasharali7583
@sayyedaamerasharali7583 3 жыл бұрын
Thanks brother this helps me a lot. 👍
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thanks for watching 🔥
@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
@asfnobambu
@asfnobambu 2 жыл бұрын
Strait to the point !! Thank you :-)
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching
@rahulkrishna164
@rahulkrishna164 3 жыл бұрын
Great video
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thanks for watching
@akashbose3682
@akashbose3682 3 жыл бұрын
Nice to watch everything u explained ❤️
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thanks for watching 🔥
@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 - kzbin.info/www/bejne/qqrGhnZvatuil8U
@techjourneyrecoded4114
@techjourneyrecoded4114 3 жыл бұрын
Really well explained!!
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you
@ZexDev
@ZexDev 2 жыл бұрын
bro that cool, thx fo this video
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad you liked it. Thanks for watching
@0xredpill
@0xredpill 2 жыл бұрын
You are amazing, you saved me from heart attack 🥰🤞🏾😋
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad you liked it!! Thanks for watching 🔥🔥
@cecibenitez3917
@cecibenitez3917 2 жыл бұрын
thanks I implemented this in my hobbie project, works perfect!
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped. Thanks for watching
@guilhermematos7448
@guilhermematos7448 2 жыл бұрын
Very helpful
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped
@clarkson9331
@clarkson9331 2 жыл бұрын
Thanks, i didnt know i can wrap code using &&. i was always doing { user ? : ... ) nice
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Glad it helped. Thanks for watching
@evoteck7273
@evoteck7273 2 жыл бұрын
I got an infinite loop after doing this keeps saying I can't call a setstate inside use Effect hook
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Please check if you have added an empty dependency array. useEffect(() => ....your code, [])
@onyilimba
@onyilimba 2 жыл бұрын
Nice tutorial, but why the background music though?
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for the feedback. Will fix this in the coming videos.
@TuanAnh-ll1lu
@TuanAnh-ll1lu 3 жыл бұрын
thank you very much
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thanks for watching
@kashmirtechtv2948
@kashmirtechtv2948 9 ай бұрын
What about showing and not showing Navbar?
@FullstackSimplified
@FullstackSimplified 9 ай бұрын
You can do the similar thing, use ternary to show/hide navbar based on auth state
@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
@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 жыл бұрын
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 жыл бұрын
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 ?
@profeskills768
@profeskills768 2 жыл бұрын
thank you :)
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks for watching
@samnayakawadi
@samnayakawadi 2 жыл бұрын
Subscribed.
@FullstackSimplified
@FullstackSimplified 2 жыл бұрын
Thanks. Really appreciate your support 🔥
@weslolo1074
@weslolo1074 2 жыл бұрын
Thank you!!!
@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.
@yotsusan_machi
@yotsusan_machi 2 жыл бұрын
note for me operator dan akan tampil jika semuanya bernilai true
@augischadiegils.5109
@augischadiegils.5109 2 жыл бұрын
❤️❤️❤️❤️❤️❤️❤️
@rinkugoswami5323
@rinkugoswami5323 3 жыл бұрын
👍
@FullstackSimplified
@FullstackSimplified 3 жыл бұрын
Thank you
@worldclasscode1847
@worldclasscode1847 2 жыл бұрын
Great video! Contact me
@soyayebhasanshafin8977
@soyayebhasanshafin8977 2 жыл бұрын
Thank you so much
React Router Tutorial - 15 - Authentication and Protected Routes
19:46
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Learn React Router v6 In 45 Minutes
46:20
Web Dev Simplified
Рет қаралды 574 М.
Custom Protected Route Component in React
10:58
Cosden Solutions
Рет қаралды 51 М.
How to Implement Dark Mode in React Like a Pro
29:09
Fullstack Simplified
Рет қаралды 3,1 М.
React Router 6 - Tutorial for Beginners
1:17:25
freeCodeCamp.org
Рет қаралды 160 М.
The New Way To Create Protected Routes With React Router V6
9:19
React Router 6 - What Changed & Upgrading Guide
29:39
Academind
Рет қаралды 174 М.
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН