🔒 How to Create a Protected Route in Express for Profile Page

🔒 How to Create a Protected Route in Express for Profile Page

T
Thapa Technical
8 Video Views·Feb 26, 2025

Want to protect routes in your Express app? In this tutorial, we'll build a protected route for the profile page using Express, JWT authentication, and middleware. We'll also cover how to check if a user is logged in, use res.locals to pass data to views, and ensure only authenticated users can access certain pages. By the end, you'll have a secure authentication system in place!

💸 Get All My YouTube Videos' Source Code for just ₹249! Grab Now - https://thapatechnical.shop/source-code

🔥 Access Source Code, PPT & Notes here for Free : https://github.com/thapatechnical/urlshortener

📺 Watch the complete Node.JS Playlist here :https://youtube.com/playlist?list=PLwGdqUZWnOp3KELplHtc-RnJ5xTUPqdgH&si=_oss

💡 Topics Covered:
✅ Checking if the user is logged in
✅ Using res.locals in Express
✅ Implementing a protected route
✅ How middleware works in authentication
✅ Step-by-step explanation with a real-world example

------------------------------------------------------------------------
🚀 Boost Your Skills with these Pre-Requisite Videos:

🔗 Best HTML Course - https://youtu.be/5ccq_nLHneE
🔗 Best CSS Course - https://youtu.be/MSICFljRcb4
🔗 JavaScript Basics Course Part 1 - https://youtu.be/13gLB6hDHR8
🔗 JavaScript Advanced Course Part 2 - https://youtu.be/YwsOCN8woA8

------------------------------------------------------------------------
💸 Build Your Own E-commerce Website for Free! - https://www.thapatechnical.com/2024/03/build-complete-ecommerce-website-using.html

------------------------------------------------------------------------
✌️ Join Us!

🚀 Become a Member: Unlock perks, free source code, and more Join Now : https://www.youtube.com/channel/UCwfaAHy4zQUb2APNOGXUCCA/join
📷 Connect on Instagram: https://www.instagram.com/thapatechnical
🗨️ Join Our Discord Server: Hang out with fellow programmers Discord Link: https://discord.gg/MdScmCsua6

------------------------------------------------------------------------

⌛TIMELINE⏳
0:00 - How to create a protected route for the profile page
0:30 - What we are going to see
1:05 - Get source code
1:55 - Showing if the user is logged in or not
4:10 - Understanding res.locals in Express
8:10 - Creating a Protected Route
10:40 - How a protected route works
11:55 - Quick recap