React Protected Routes | Role-Based Authorization | React Router v6
Dave Gray
@davegrayteachescodeAbout
Web Development tutorials with full courses on HTML, CSS, JavaScript, React, Node.js and more! My goal is to help you learn how to build the web. Teaching helps me learn, too. I work full-time as a Solutions Architect / Developer and part-time as a university web dev instructor. Thank you for subscribing, supporting my channel and sharing the videos you think may help others. Keep striving for progress over perfection. And a little progress every day goes a very long way. Milestones: July 20, 2020 - 1st video Jan 1, 2021 - 1k subs April 2021 - 4k watch hours Nov 2021 - 10k subs Jan 21, 2022 - Video at 100k views Feb 16, 2022 - 100k watch hours Feb 19, 2022 - 1m views Dec 13, 2022 - 100k subs Dec 2022 - Over 1m views in 1 month April 7, 2023 - 10m views May 26, 2023 - 1m watch hours Sept 22, 2023 - Video at 1m views Dec 25, 2023 - 250k subs
Video Description
Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmap React Protected Routes allows you to make part of your React app exclusive to authorized users. Role-Based Authorization allows different levels of access based upon the assigned user roles. This tutorial utilizes React Router v6. ๐ Support me on Patreon โ https://patreon.com/davegray โญ Become a full-stack web dev with Zero To Mastery Courses: - Advanced React & Redux: https://bit.ly/AdvReactDev - Jr to Senior Web Dev Roadmap: https://bit.ly/WebDevRoadmap-JrtoSr - Master FAANG Coding Interviews: https://bit.ly/FAANGInterview ๐ฉ Subscribe โ https://bit.ly/3nGHmNn ๐ React JS for Beginners full course - 9 hours: https://youtu.be/RVFAyFWO4go ๐ Source Code: https://github.com/gitdagray/react_protected_routes ๐ฌ Course Updates โ https://courses.davegray.codes/ React Protected Routes | Role-Based Authorization | React Router v6 (00:00) Intro (00:53) Welcome and Startup (01:27) Install React Router v6 (02:17) Update index.js with RRv6 (03:38) Basic Routing Setup (07:41) useAuth hook (10:06) RequireAuth component v1 (14:38) Manage browser history (18:50) Testing with backend authentication (21:00) RequireAuth component v2 (24:26) Applying Role-Based Routing (26:35) Object lookup for roles (28:15) Testing role-based routes (29:37) Last note on the Unauthorized component โ Buy Me A Coffee: https://www.buymeacoffee.com/davegray ๐ React Router Version 6 in 20 minutes: https://youtu.be/XBRLVRjZ3CQ ๐ React User Login and Authentication with Axios: https://youtu.be/X3qyxo_UTR4 ๐ React Register Form with Validation, Axios and a11y: https://youtu.be/brcHK3P6ChQ ๐ Node JS Full Course (with source code) for building the backend REST API that will receive your form submissions: https://youtu.be/f2EqECiTBL8 ๐ FontAwesome for React: https://fontawesome.com/v5.15/how-to-use/on-the-web/using-with/react ๐ RegExr for Regular Expressions: https://regexr.com/ ๐ Accessible Form References: WebAIM.org - Advanced Forms: https://webaim.org/techniques/forms/advanced WebAIM.org - Form Validation: https://webaim.org/techniques/formvalidation/ MDN - Aria Attributes: aria-invalid: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-invalid_attribute aria-describedby: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby aria-live: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live aria-label: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label ๐ ES7 React JS Snippets Extension for VS Code: https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets ๐ React Dev Tools Extension for Chrome: https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi ๐ References: ReactJS Official site: https://reactjs.org/ React Wikipedia: https://en.wikipedia.org/wiki/React_(JavaScript_library) React Jobs: https://www.ziprecruiter.com/candidate/search?search=react&location= โ Follow Me: Github: https://github.com/gitdagray Twitter: https://twitter.com/yesdavidgray LinkedIn: https://www.linkedin.com/in/davidagray/ Blog: https://yesdavidgray.com Reddit: https://www.reddit.com/user/DaveOnEleven Was this tutorial about creating protected routes and role-based user authorization in React with React Router v6 helpful? If so, please share. Let me know your thoughts in the comments. #react #protected #routes
Instant DIY Phone Stand Solutions
AI-recommended products based on this video
![Mibly [125 Count] 6 Inch Jumbo Multipurpose wooden Popsicle sticks, Wood Craft Supplies, Lollipop Lolly Sticks, Wooden Tongue Depressor, Wax Sticks for Waxing, Ice Cream Sticks](https://m.media-amazon.com/images/I/618FQ2N2uZL._AC_UL960_FMwebp_QL65_.jpg)
Mibly [125 Count] 6 Inch Jumbo Multipurpose wooden Popsicle sticks, Wood Craft Supplies, Lollipop Lolly Sticks, Wooden Tongue Depressor, Wax Sticks for Waxing, Ice Cream Sticks

Portable Plastic Cereal Cup for Breakfast Easy to Carry to Go Cereal and Milk Container

Telaso for Samsung Galaxy S25 Case, 360ยฐ Rotation Kickstand Ring Holder Plating Edge Soft Rubber TPU Bumper Slim Flexible Shockproof Protective Phone Case Cover for Samsung S25 2025,Sapphire Blue

Telaso for Samsung Galaxy S25 Case, 360ยฐ Rotation Kickstand Ring Holder Plating Edge Soft Rubber TPU Bumper Slim Flexible Shockproof Protective Phone Case Cover for Samsung S25 2025, Gray Green

Yuyul 100Pcs Harry Stickers, Vinyl Waterproof Cartoon Stickers for Skateboard, Laptop, Scrapbook, Luggage, Phone, Gift for Boys, Teens, Adults DIY Decor

3 in 1 Wireless Charger,RTOPS Fodable Charging Stations for Multiple Apple Devices, W312 Fast Travel Charging Stand for Airpod, iWatch and Phone 12-15 (Adapter Included)

JoyGeek 3-in-1 Magnetic Wireless Charging Station for iPhone 16/15/14/13/12 Series & Apple Watch Ultra 2/SE; 360ยฐ Adjustable Phone Stand with 18W Adapter, Compatible with AirPods Pro/3/2 Recycled Claim Standard Blended

Ladders Telescoping Ladder 12.5 FT Dual Purpose Aluminum Telescopic Ladder with Non-Slip Feet Adjustable Lightweight Compact Ladders for Household or RV Outdoor Work,330lb Load Capacity(1.9M+1.9M)

Telescoping Aluminum Ladder 16.5 FT Dual Purpose With Stabilizer - Adjustable Compact Step Climb for Household, RV, Outdoor Work - 330lb Load Capacity (2.5M+2.5M)

RIKADE Telescoping Ladder, A-Frame Aluminum Telescopic Ladder with 1 Button Retraction, Portable Extension Ladder Adjustable Lightweight Folding Ladder for Home or RV Work, 330lb Capacity

2025 New Upgrade Adjustable Work Platform Step Ladders Support 800 lbs, 33" x12" x20" Non Slip Folding Aluminum Platform Step Stool for Household Office Cleaning & Washing

Kohentact Hidden Suspenders for Men 1.5'' Heavy-Duty Under Clothes 3 Snap Loops Outdoor & Skiing

Zinus Adjustable Bed Frame, Twin to Queen - Compack 7 Inch Metal Bed Frame for Box Spring , 9 Legs Heavy-Duty Frame, Easy Assembly, Headboard Compatiable with Built-in Bracket, Mattress Support

GuirCygne GuirCygne Travel Cup Holder for Luggage โ Robust Reliable, Secure Convenient, 2-Cup Capacity, Fit Most Roll-on Suitcases, Heavy-Duty Waterproof Easy to Install, Perfect for Frequent Travelers Leopard

LEGO Technic Heavy-Duty Bulldozer Building Set, Kidsโ Construction Toy, Vehicle Gift for Boys and Girls Ages 7 and Up, 42163

eazpower for Magsafe Power Bank 10000mAh, Magnetic Battery Pack Wireless, 20W PD Fast Charging, Compact Portable Charger with Built-in Cables and Stand for iPhone 16/15/14/13/12/ Apple Watch/Airpods

24" Large Portable Monitor, 1080P FHD 100Hz Laptop Screen Extender, 125% sRGB IPS Monitor Extender, USB C HDMI Office Gaming with Detachable Stand, Travel Monitor for Window MAC Phone Xbox Switch

UPERFECT Portable Monitor 17.3 Inch 2K 144Hz Portable Gaming Monitor Travel Monitor for Laptop 2560x1440P HDR IPS Screen with VESA, Cover Stand, Dual Speakers for PC Phone Game Console

InnoView Portable Monitor Touchscreen 15.6" 1080P 10-Point Touch Screen Monitor Portable with Protective Sleeve Built-in Stand, 1200:1 HDMI USB C Travel Monitors for Laptop, PC, Mac, Phone, Switch

16" Portable Monitor for Laptop - 1200P FHD Travel Monitor for Laptop IPS LCD USB C/USB A/HDMI Second Screen with Stand Gaming Monitor for PC MAC Computer Switch Phone Xbox PS4/5

Wireless Charger, 3 in 1 Charging Station, Fast Charging Station Foldable Charging Stand, Wireless Charging Station for Multiple Devices, Compatible with lPhone 17/16/15/14/13 Pro Max Airpods Watch

Wireless Charger, 3 in 1 Charging Station, Fast Charging Station Foldable Charging Stand, Wireless Charging Station for Multiple Devices, Compatible with lPhone 16/15/14/13 Pro Max Airpods Watch




















