Recall & Review
beginner
What is route protection in Express?
Route protection means controlling access to certain routes based on user roles or authentication status to keep parts of the app secure.
Click to reveal answer
beginner
How do you check if a user is an admin in Express middleware?
You check the user's role stored in the request (like req.user.role) and allow access only if it equals 'admin'.
Click to reveal answer
beginner
Why separate admin routes from user routes?
Separating routes helps keep admin functions secure and prevents regular users from accessing sensitive actions.
Click to reveal answer
beginner
What happens if a user tries to access an admin route without permission?
The middleware blocks access and usually sends a 403 Forbidden response or redirects the user.
Click to reveal answer
intermediate
How can you reuse route protection logic in Express?
By creating middleware functions that check roles and applying them to routes that need protection.
Click to reveal answer
What Express feature is commonly used to protect routes based on user roles?
✗ Incorrect
Middleware functions run before route handlers and can check user roles to allow or deny access.
If a user is not an admin, what HTTP status code should you send when blocking access?
✗ Incorrect
403 Forbidden means the server understood the request but refuses to authorize it.
Where is user role information typically stored for route protection?
✗ Incorrect
User info like roles is usually attached to req.user after authentication or stored in session.
What is a good practice to avoid repeating role checks in many routes?
✗ Incorrect
Middleware lets you write role checks once and apply them to many routes easily.
Which of these is NOT a reason to protect admin routes separately?
✗ Incorrect
Protecting routes does not intentionally slow them down; it secures access.
Explain how you would protect an admin route in Express using middleware.
Think about checking user role before allowing access.
You got /4 concepts.
Why is it important to separate admin and user routes in a web app?
Consider what could happen if users access admin features.
You got /4 concepts.