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

Dave Gray β€’ January 14, 2022
Video Thumbnail
Dave Gray Logo

Dave Gray

View Channel

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...
FNTCASE for iPhone 17 Pro-Max Case: Clear Magnetic Phone Cases with Screen Protector Compatible with Magsafe Slim Anti Yellowing Rugged Shockproof Protective Transparent Cell Cover (A-Clear) Recycled Claim Standard Blended

FNTCASE for iPhone 17 Pro-Max Case: Clear Magnetic Phone Cases with Screen Protector Compatible with Magsafe Slim Anti Yellowing Rugged Shockproof Protective Transparent Cell Cover (A-Clear) Recycled Claim Standard Blended

(0)
$3.95
FREE delivery Wed, Nov 19 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
TOCOL for iPhone 17 Pro Case, Full Camera Protection, Built-in Magnetic Ring, Compatible with Magsafe Charger, Drop Protection, Translucent Matte Phone Case for iPhone 17 Pro 6.3 inch (Black) Global Recycled Standard
Best Seller

TOCOL for iPhone 17 Pro Case, Full Camera Protection, Built-in Magnetic Ring, Compatible with Magsafe Charger, Drop Protection, Translucent Matte Phone Case for iPhone 17 Pro 6.3 inch (Black) Global Recycled Standard

(23,902)
$9.99
FREE delivery Mon, Sep 29 on $35 of items shipped by Amazon
New on Amazon in past month
Loading...
Lamicall Bike Phone Holder, Motorcycle Mount - Motorcycle Phone Holder, Handlebar Cell Phone Clamp, Scooter Phone Clip for iPhone Air 17 Pro Max, 16 15 Pro Max Plus, S20, More 4.7 to 6.8" Smartphones Global Recycled Standard
Best Seller

Lamicall Bike Phone Holder, Motorcycle Mount - Motorcycle Phone Holder, Handlebar Cell Phone Clamp, Scooter Phone Clip for iPhone Air 17 Pro Max, 16 15 Pro Max Plus, S20, More 4.7 to 6.8" Smartphones Global Recycled Standard

(61,683)
$15.99$15.83
FREE delivery Sun, Sep 21 on $35 of items shipped by Amazon
30K+ bought in past month
Loading...
Car Phone Holder for Magsafe [78+LBS Strongest Suction & 2400gf Magnetic] 360Β° Adjustable Car Phone Mount, Phone Holders for Your Car for iPhone 17 Pro Max 16 15 14 13 12 Air Plus (Carbon Fiber) Global Recycled Standard
Best Seller

Car Phone Holder for Magsafe [78+LBS Strongest Suction & 2400gf Magnetic] 360Β° Adjustable Car Phone Mount, Phone Holders for Your Car for iPhone 17 Pro Max 16 15 14 13 12 Air Plus (Carbon Fiber) Global Recycled Standard

(10,765)
$26.99$26.45
FREE delivery Fri, Oct 3 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Selfie Stick Travel Tripod for Cell Phone with Remote Control and Phone Holder, Extendable Selfie Stick for iPhone, iPhone Tripod for Video Recording, 50 Inch, Black

Selfie Stick Travel Tripod for Cell Phone with Remote Control and Phone Holder, Extendable Selfie Stick for iPhone, iPhone Tripod for Video Recording, 50 Inch, Black

(3,610)
$9.99
FREE delivery Fri, Nov 14 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Hydrocolloid Bandages for Wound Care, Extra Large Medical-Grade Hydrocolloid Roll with Self-Adhesive, Ultra Absorbent, Flexible & Waterproof, DIY Size & Shape First Aid Kit Essential (2in*4.8ft)

Hydrocolloid Bandages for Wound Care, Extra Large Medical-Grade Hydrocolloid Roll with Self-Adhesive, Ultra Absorbent, Flexible & Waterproof, DIY Size & Shape First Aid Kit Essential (2in*4.8ft)

(126)
$8.99
FREE delivery Fri, Oct 3 on $35 of items shipped by Amazon
8K+ bought in past month
Loading...
Etercycle Nail Stand Acrylic Nail Art Display Stand Practice Nail Holder for Painting Nails Magnetic Practice Stands with Double-sided Tape For DIY Salon Supplies (Pink)

Etercycle Nail Stand Acrylic Nail Art Display Stand Practice Nail Holder for Painting Nails Magnetic Practice Stands with Double-sided Tape For DIY Salon Supplies (Pink)

(909)
$4.99
FREE delivery Sun, Dec 28 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
MagSafe Charger 2 Pack 15W Magnetic Wireless Charger Fast Charging Pad Compatible with iPhone 17/16/15/14/13/12 Series & AirPods 3/2/Pro Magnetic MagSafe Charging Pad with Dual Ports ClimeCo Certified

MagSafe Charger 2 Pack 15W Magnetic Wireless Charger Fast Charging Pad Compatible with iPhone 17/16/15/14/13/12 Series & AirPods 3/2/Pro Magnetic MagSafe Charging Pad with Dual Ports ClimeCo Certified

(6,051)
$13.28
FREE delivery Fri, Nov 14 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Golvery Bluetooth 5.3 True Wireless Earbuds w/DSP Noise Cancelling Mic, Open Ear Stereo Sports Headphones w/ 800mAh LCD Display Charging Base, HiFi Deep Bass, Compatible with TV iPhone Android

Golvery Bluetooth 5.3 True Wireless Earbuds w/DSP Noise Cancelling Mic, Open Ear Stereo Sports Headphones w/ 800mAh LCD Display Charging Base, HiFi Deep Bass, Compatible with TV iPhone Android

(81)
15.19
PrimeFREE delivery Saturday, June 14 on orders shipped by Amazon over $35
Loading...
Apple AirPods 4 Wireless Earbuds, Bluetooth Headphones, Personalized Spatial Audio, Sweat and Water Resistant, USB-C Charging Case, H2 Chip, Up to 30 Hours of Battery Life, Effortless Setup for iPhone
Best Seller

Apple AirPods 4 Wireless Earbuds, Bluetooth Headphones, Personalized Spatial Audio, Sweat and Water Resistant, USB-C Charging Case, H2 Chip, Up to 30 Hours of Battery Life, Effortless Setup for iPhone

(23,152)
$89.99$83.69
FREE delivery Thu, Sep 4
10K+ bought in past month
Loading...
Wireless Earbuds Bluetooth V5.3 Headphones 50H Playback Deep Bass Stereo Ear Buds with LED Power Display Charging Case IPX7 Waterproof Earphones with Mic Headset for Laptop Pad Android/iOS Phones

Wireless Earbuds Bluetooth V5.3 Headphones 50H Playback Deep Bass Stereo Ear Buds with LED Power Display Charging Case IPX7 Waterproof Earphones with Mic Headset for Laptop Pad Android/iOS Phones

(1,809)
$6.99
FREE delivery Jun 17 - 20 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Younik Switch Accessories Bundle, 17 in 1 Purple Switch Accessories Kit for Girls Include Switch Carrying Case, Adjustable Stand, Protective Case for Switch Console & J-Con

Younik Switch Accessories Bundle, 17 in 1 Purple Switch Accessories Kit for Girls Include Switch Carrying Case, Adjustable Stand, Protective Case for Switch Console & J-Con

(3,720)
$20.99
FREE delivery Mon, Jun 16 on $35 of items shipped by Amazon
200+ bought in past month
Loading...
Car Phone Holder for Magsafe [78+LBS Strongest Suction & 2400gf Magnetic] 360Β° Adjustable Car Phone Mount, Phone Holders for Your Car for iPhone 17 Pro Max 16 15 14 13 12 Air Plus (Carbon Fiber) Global Recycled Standard
Best Seller

Car Phone Holder for Magsafe [78+LBS Strongest Suction & 2400gf Magnetic] 360Β° Adjustable Car Phone Mount, Phone Holders for Your Car for iPhone 17 Pro Max 16 15 14 13 12 Air Plus (Carbon Fiber) Global Recycled Standard

(10,765)
$26.99$26.45
FREE delivery Fri, Oct 3 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Book Stand for Reading, Adjustable Book Holder with 360Β° Rotating Bases, Foldable Designs, and Elastic Clips, Multifunctional Display Stand for Recipe, Cookbooks, Magazines, Tablets, Laptops

Book Stand for Reading, Adjustable Book Holder with 360Β° Rotating Bases, Foldable Designs, and Elastic Clips, Multifunctional Display Stand for Recipe, Cookbooks, Magazines, Tablets, Laptops

(388)
22.39
PrimeFREE delivery Saturday, June 14 on orders shipped by Amazon over $35
2K+ bought in past month
Loading...
CAHAYA Portable Sheet Music Stand: Dual Use Desktop Book Holder Folding Lightweight Extra Stable Reinforced with Carrying Bag and Clip for Students Musicians Height Adjustable up to 54.3" CMS0204
Best Seller

CAHAYA Portable Sheet Music Stand: Dual Use Desktop Book Holder Folding Lightweight Extra Stable Reinforced with Carrying Bag and Clip for Students Musicians Height Adjustable up to 54.3" CMS0204

(13,595)
$14.99$14.84
FREE delivery Thu, Sep 4 on $35 of items shipped by Amazon
5K+ bought in past month
Loading...
FIFINE USB/XLR Dynamic Microphone for Podcast Recording, PC Computer Gaming Streaming Mic with RGB Light, Mute Button, Headphones Jack, Desktop Stand, Vocal Mic for Singing YouTube-AmpliGame AM8 Global Recycled Standard ClimatePartner certified
Best Seller

FIFINE USB/XLR Dynamic Microphone for Podcast Recording, PC Computer Gaming Streaming Mic with RGB Light, Mute Button, Headphones Jack, Desktop Stand, Vocal Mic for Singing YouTube-AmpliGame AM8 Global Recycled Standard ClimatePartner certified

(6,248)
$54.99
FREE delivery Thu, Sep 4
8K+ bought in past month
Loading...
Eye Contact Web Camera for Desktop Computer – 1080P USB Camera with Microphone & Stand, Center Cam for Laptop or Desktop, Manual Focus, Plug & Play for macOS & Windows(BlackοΌ‰

Eye Contact Web Camera for Desktop Computer – 1080P USB Camera with Microphone & Stand, Center Cam for Laptop or Desktop, Manual Focus, Plug & Play for macOS & Windows(BlackοΌ‰

(96)
37.39
PrimeFREE delivery Saturday, June 14
100+ bought in past month
Loading...
CAHAYA Portable Sheet Music Stand: Dual Use Desktop Book Holder Folding Lightweight Extra Stable Reinforced with Carrying Bag and Clip for Students Musicians Height Adjustable up to 54.3" CMS0204
Best Seller

CAHAYA Portable Sheet Music Stand: Dual Use Desktop Book Holder Folding Lightweight Extra Stable Reinforced with Carrying Bag and Clip for Students Musicians Height Adjustable up to 54.3" CMS0204

(13,595)
$14.99$14.84
FREE delivery Thu, Sep 4 on $35 of items shipped by Amazon
5K+ bought in past month
Loading...
Selfie Stick Travel Tripod for Cell Phone with Remote Control and Phone Holder, Extendable Selfie Stick for iPhone, iPhone Tripod for Video Recording, 50 Inch, Black

Selfie Stick Travel Tripod for Cell Phone with Remote Control and Phone Holder, Extendable Selfie Stick for iPhone, iPhone Tripod for Video Recording, 50 Inch, Black

(3,610)
$9.99
FREE delivery Fri, Nov 14 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
FNTCASE for iPhone 17 Pro-Max Case: Clear Magnetic Phone Cases with Screen Protector Compatible with Magsafe Slim Anti Yellowing Rugged Shockproof Protective Transparent Cell Cover (A-Clear) Recycled Claim Standard Blended

FNTCASE for iPhone 17 Pro-Max Case: Clear Magnetic Phone Cases with Screen Protector Compatible with Magsafe Slim Anti Yellowing Rugged Shockproof Protective Transparent Cell Cover (A-Clear) Recycled Claim Standard Blended

(0)
$3.95
FREE delivery Wed, Nov 19 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
ESR for iPhone 17 Pro Max Case, Camera Control, Compatible with MagSafe, Shockproof Military-Grade Protection, Magnetic Phone Case for iPhone 17 Pro Max, Classic Hybrid Case, Clear Carbonfree Certified

ESR for iPhone 17 Pro Max Case, Camera Control, Compatible with MagSafe, Shockproof Military-Grade Protection, Magnetic Phone Case for iPhone 17 Pro Max, Classic Hybrid Case, Clear Carbonfree Certified

(127,198)
$8.49
FREE delivery Fri, Oct 3 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Apple EarPods Headphones with USB-C Plug, Wired Ear Buds with Built-in Remote to Control Music, Phone Calls, and Volume

Apple EarPods Headphones with USB-C Plug, Wired Ear Buds with Built-in Remote to Control Music, Phone Calls, and Volume

(18,713)
$16.99$14.90
FREE delivery Tue, Nov 4 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Wireless Bluetooth Mouse for Apple iPad iPhone MacBook Android Samsung Tablet Phone Dual-Mode Rechargeable 2.4G Portable Computer Mice for Windows Laptop Notebook PC Mac Desktop USB Receiver (Black)

Wireless Bluetooth Mouse for Apple iPad iPhone MacBook Android Samsung Tablet Phone Dual-Mode Rechargeable 2.4G Portable Computer Mice for Windows Laptop Notebook PC Mac Desktop USB Receiver (Black)

(1,960)
9.99
PrimeFREE delivery Saturday, June 14 on orders shipped by Amazon over $35
500+ bought in past month
Loading...
UPERFECT Portable Monitor 18.5 inch 120 Hz 100% sRGB 1080P Portable Screen for Laptop w/Smart Cover, VESA & Speakers, Frameless IPS HDR USB-C HDMI Port Gaming Monitor for Smart Phone, Tablet, MacBook

UPERFECT Portable Monitor 18.5 inch 120 Hz 100% sRGB 1080P Portable Screen for Laptop w/Smart Cover, VESA & Speakers, Frameless IPS HDR USB-C HDMI Port Gaming Monitor for Smart Phone, Tablet, MacBook

(1,775)
129.99
PrimeFREE delivery Saturday, June 14
50+ bought in past month
Loading...
Selfie Stick Travel Tripod for Cell Phone with Remote Control and Phone Holder, Extendable Selfie Stick for iPhone, iPhone Tripod for Video Recording, 50 Inch, Black

Selfie Stick Travel Tripod for Cell Phone with Remote Control and Phone Holder, Extendable Selfie Stick for iPhone, iPhone Tripod for Video Recording, 50 Inch, Black

(3,610)
$9.99
FREE delivery Fri, Nov 14 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
FNTCASE for iPhone 17 Pro-Max Case: Clear Magnetic Phone Cases with Screen Protector Compatible with Magsafe Slim Anti Yellowing Rugged Shockproof Protective Transparent Cell Cover (A-Clear) Recycled Claim Standard Blended

FNTCASE for iPhone 17 Pro-Max Case: Clear Magnetic Phone Cases with Screen Protector Compatible with Magsafe Slim Anti Yellowing Rugged Shockproof Protective Transparent Cell Cover (A-Clear) Recycled Claim Standard Blended

(0)
$3.95
FREE delivery Wed, Nov 19 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
ESR for iPhone 17 Pro Max Case, Camera Control, Compatible with MagSafe, Shockproof Military-Grade Protection, Magnetic Phone Case for iPhone 17 Pro Max, Classic Hybrid Case, Clear Carbonfree Certified

ESR for iPhone 17 Pro Max Case, Camera Control, Compatible with MagSafe, Shockproof Military-Grade Protection, Magnetic Phone Case for iPhone 17 Pro Max, Classic Hybrid Case, Clear Carbonfree Certified

(127,198)
$8.49
FREE delivery Fri, Oct 3 on $35 of items shipped by Amazon
10K+ bought in past month
Loading...
Apple EarPods Headphones with USB-C Plug, Wired Ear Buds with Built-in Remote to Control Music, Phone Calls, and Volume

Apple EarPods Headphones with USB-C Plug, Wired Ear Buds with Built-in Remote to Control Music, Phone Calls, and Volume

(18,713)
$16.99$14.90
FREE delivery Tue, Nov 4 on $35 of items shipped by Amazon
10K+ bought in past month