Recall & Review
beginner
What is the main purpose of middleware in Next.js?
Middleware in Next.js runs before a request reaches a page or API route. It lets you check or change the request, like redirecting users or adding headers.
Click to reveal answer
beginner
How does middleware help with authentication in Next.js?
Middleware can check if a user is logged in before letting them access a page. If not logged in, it can redirect them to a login page.
Click to reveal answer
intermediate
Why might middleware modify a request before it reaches a page?
Middleware can add or change request details, like headers or cookies, to control how the page handles the request or to add security.
Click to reveal answer
intermediate
What is one benefit of intercepting requests with middleware instead of inside page code?
Middleware runs early and can stop or redirect requests before loading a page, making the app faster and more secure by avoiding unnecessary page loads.
Click to reveal answer
beginner
Can middleware in Next.js run on both server and client sides?
No, Next.js middleware runs only on the server side during the request phase to intercept and handle requests before pages load.
Click to reveal answer
What does Next.js middleware do with incoming requests?
✗ Incorrect
Middleware intercepts requests early to modify or redirect them before pages handle them.
Why use middleware for authentication checks in Next.js?
✗ Incorrect
Middleware can stop unauthorized users early by redirecting them before pages load.
Where does Next.js middleware run?
✗ Incorrect
Middleware runs on the server to handle requests before pages load.
Which of these is NOT a reason to use middleware in Next.js?
✗ Incorrect
Styling pages is done in components, not middleware.
What happens if middleware redirects a request?
✗ Incorrect
Middleware redirect stops the original page from loading and sends the user elsewhere.
Explain why middleware intercepts requests in Next.js and how this helps improve app behavior.
Think about what happens before a page shows up.
You got /4 concepts.
Describe a real-life example where middleware intercepting a request would be useful in a Next.js app.
Imagine a locked door that only lets certain people in.
You got /4 concepts.