React Protected Routes | Role-Based Authorization | React Router v6
Dave Gray
View ChannelAbout
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
Latest Posts
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

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

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

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
![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](https://m.media-amazon.com/images/I/712lUnThXpL._AC_UL960_FMwebp_QL65_.jpg)
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

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

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)

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)

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

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

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

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

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
![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](https://m.media-amazon.com/images/I/712lUnThXpL._AC_UL960_FMwebp_QL65_.jpg)
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

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

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

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

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οΌ

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

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

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

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

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

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)

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

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

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

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





































