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

Dave Gray โ€ข January 14, 2022
Video Thumbnail

About

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

You May Also Like

Instant DIY Phone Stand Solutions

AI-recommended products based on this video

Loading...
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

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

(110)
$6.29
FREE delivery Thu, Sep 11 on your first order
800+ bought in past month
Loading...
Portable Plastic Cereal Cup for Breakfast Easy to Carry to Go Cereal and Milk Container

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

(3)
$13.49$11.79
FREE delivery Jan 2 - 6
600+ bought in past month
Loading...
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,Sapphire Blue

(122)
$14.99
FREE delivery Sun, Jun 15 on your first order
Loading...
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

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

(122)
$12.99
FREE delivery Sat, Jun 14 on your first order
100+ bought in past month
Loading...
Yuyul 100Pcs Harry Stickers, Vinyl Waterproof Cartoon Stickers for Skateboard, Laptop, Scrapbook, Luggage, Phone, Gift for Boys, Teens, Adults DIY Decor

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

(29)
$9.88
FREE delivery Sat, Jun 14 on your first order
Loading...
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)

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)

(739)
$29.99
FREE delivery Tue, Nov 25 on your first order
200+ bought in past month
Loading...
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

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

(959)
$19.99
FREE delivery Sat, Jun 14 on your first order
Loading...
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)

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)

(82)
$136.79$127.99
FREE delivery Sat, Jun 28
Loading...
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)

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)

(660)
$179.54$153.99
FREE delivery Sat, Jun 28
Loading...
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

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

(522)
$145.99
Loading...
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

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

(2)
$189.90
FREE delivery Sat, Jun 28
Loading...
Kohentact Hidden Suspenders for Men 1.5'' Heavy-Duty Under Clothes 3 Snap Loops Outdoor & Skiing

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

(136)
$22.49
FREE delivery Jul 2 - 23
50+ bought in past month
Loading...
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

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

(61,640)
$56.44$50.80
FREE delivery Wed, Jun 25
200+ bought in past month
Loading...
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

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

(1)
$15.99
FREE delivery Sun, Jul 6 on your first order
Loading...
LEGO Technic Heavy-Duty Bulldozer Building Set, Kidsโ€™ Construction Toy, Vehicle Gift for Boys and Girls Ages 7 and Up, 42163

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

(782)
$11.99
FREE delivery Sat, Jun 14 on your first order
300+ bought in past month
Loading...
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

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

(330)
$39.99
PrimeFREE delivery Sat, Jun 14
200+ bought in past month
Loading...
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
Amazon's Choice

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

(56)
$335.99$299.99
$19.94 delivery Mon, Aug 11
Loading...
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

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

(2,824)
$389.49
PrimeOnly 8 left in stock.
Loading...
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

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

(2,004)
$169.99
FREE delivery Mon, Aug 11
100+ bought in past month
Loading...
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

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

(46)
$149.99
FREE delivery Sun, Aug 10
Loading...
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 17/16/15/14/13 Pro Max Airpods Watch

(156)
$25.64
FREE delivery Wed, Dec 24 on your first order
3K+ bought in past month
Loading...
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

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

(126)
$42.99$30.99
FREE delivery Sun, Oct 26
1K+ bought in past month
Loading...
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

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

(208)
$28.99
FREE delivery Mon, Jul 7 on your first order
1K+ bought in past month