How to create Protected Routes and Authentication with React Router V6 2023
HTML-код
- Опубликовано: 24 авг 2024
- Download the code here - github.com/Kod...
In this video, we'll be learning how to create protected routes and authentication with React Router V6. Private routes allow us to control how specific paths are accessible, while authentication provides a secure way to ensure only authorised users can access our content.
By the end of this video, you'll be able to create private routes and authentication in React Router V6, ensuring that your users are protected while they access your content
Using React Router V6 we'll put together an App that has:
1. Authentication wrapper using useContext and useReducer
2. A custom component to build our routes and menu options
3. A login page that calls a login function from our Auth Wrapper
4. Dynamically build and set our menus and routes depending on the user's status
#reacttutorial #reactrouter #reactjs
This video is just pure gold! Straightforward, concise, without any useless information. Amazing!
Glad you enjoyed it!
This video was exactly what I needed!! I've been confused with authentication and the bunch of different ways to do it and a video that cuts all the extra stuff and shows you the basics of how it works was perfect. Thanks so much, hope you make more videos was sad to see this was your latest on in a year.
You deserved more subscribers. You are a good example on what the developers should follow. I haven't followed yours but I created something that is similar and in tsx.
I appreciate that!
straight and easy to understand thanks for the video.
Amazing video! I love how there are people like you that go straight to the point and explain in plain English. Thanks a lot for the video! PS: Better teaching methods than my university (will definitely suggest to my friends)!
Really appreciate the feedback!
This is a super useful video!!!, went through it, understood how everything is done, great video!!!
Gold Gold Goldberg !! Happy to find this channel !!
Good luck with your channel. Liked your content
I appreciate it!
your content is amazing seriously. i learned so much from this single video of yours,
Awesome, thank you!
I enjoyed the video and your accent, as well as learned from you
Thanks for the feedback!
Excellent content!!!!! Thank you very much 🤓 I would love to see another tutorial with your implementation of local storage.
Great suggestion!
@@kodieCode it looks like maybe you're not making these videos anymore, but consider this comment as another vote for a video on the local storage
Nice, simple, to the point.
Thanks!
Glad it helped!
yo bro
thank u sooo much, i every day look yt, and try to learn something new, and u speak very easy for me! (sorry for my eng)
gl bro at ur way!
Thanks for the kind comments!
Great and concise 👍
Glad it was helpful!
Thank you! The map part is genius
Thanks for feedback
Thanks for the helpful tutorial!!!
Glad it was helpful!
i love it great knowledge been passed here, thanks a lot
My pleasure!
It's amazing! thank you very much!
Glad you like it!
Nice ❤
Great content. Please release a video about refresh and access tokens
Thanks for the suggestion. I'll be working on that video soon
Hey @@kodieCode any update?
Good work!
Thanks!
thanks you for this tut
Welcome 😊
Really nice video, Thankyou.
Glad you liked it!
Cool video! Simple and well explained! It would be very helpful to see an implementation with local storage as well as role-based authorization. Regardless, thanks for the awesome content!
Great suggestion!
Great content, thx!
Thanks for the feedback
Hi @kodie,
Great content here. However, I'd prefer to show the login page if a user tries to access a private page
This is easy enough to do with creating a default route pointing at the login page. That means any route not created based on their status, will show that page instead.
Thank You so much!!!
You're very welcome!
How do we add google auth to this?
I'm planning to do a video on various third party Auth libraries including Google very soon.
@@kodieCode Thanks!
@@kodieCode waiting for the video man!!
can you make a new video on how not to make user logout whenever the page refresh?
thank you
Welcome!
yes pls do that user key and session expire thingi we do want it
Please I need a tutorial on how to use localstorage with this
I suggest that you make code along tutorials, with more catchy thumbnails. Your content is great, you will grow fast.
Thanks for the tip
How can I Implement roles of users?
why on refresh it does not hold the private links? It resets and I have to click on "login" again so they pop up
This is because in that tutorial we are not storing that the user is authenticated in the localStorage or a cookie. This means a refresh of the page restarts the state. I am working on a video to expand on this authentication method and show how to start storing user details including if the user is logged in so that a returning user might be automatically authenticated
This only dynamicly shows the menu items. If a user is not logged in it still can go to the private route by typing it in. There is no redirect.
The routes are only accessible when logged in as the routes are only defined when authenticated therefore not accessible. If a user not logged in tries to directly access a private route they will be shown the default controller
Wow never thought of setting it up like that. Makes absolute sense. An aha moment for me. Thanks for the reply.
No problem. The great thing about an overall Auth controller with useContext is that you can make just about anything easily conditional on the user being logged in.
But what If the user enters to that route from a different tab, he is logged in but since the state of user logged in is only on the other tab, now he wont have access? @@kodieCode
This is okay but how can we show 404 page and not authenticated user according to condition.
can you help me to do same thing in next.js,
i have to do with user role based , their tho 2 user role , so how to do in next.js with typescript?
heyy kodie how about make a simple tutorial that is in ts not js and handle auth via jwt cookie not token to be more secure then use R.R.D v6 to protect the routes
Great suggestion. Thanks for the feedback.
@@kodieCode
Btw remember my words your channel will grow super fast cause everything is good the audio the video's quality and also the content keep up the good work
Why are the extension files `.js` instead of `.jsx`?
Doesn't matter it's a framework
how to add role user sir
You would need to add an additional object against the user to define their role and then load the routes depending on what that role is allowed to access.
rooutah
Thanks