Quiz: Route Handlers, Proxy and Authentication
Explore how to structure API routes, manage proxy rewrites versus redirects for access control, and implement authentication in Next.js applications. Learn to design endpoints and choose routing strategies for secure, flexible features.
Multiple choice questions
What is the fundamental difference between NextResponse.rewrite() and NextResponse.redirect() in Next.js middleware?
rewrite serves content from a different path without changing the URL, while redirect sends the browser to a new URL.
rewrite changes the URL in the browser’s address bar, while redirect serves different content for the same URL.
rewrite is used for permanent URL changes (308 status), while redirect is for temporary changes (307 status).
rewrite can only be used with the matcher config, while redirect works for all routes by default.
Matching exercise
Match the NextAuth.js concept or function to its correct description.
auth() (server-side)
A React hook used in Client Components to access the current user’s session data
Proxy
Functions exported from a route.js file within the app/api directory to build API endpoints
Route Handler
A helper function imported from @/auth to securely get the session object in Server Components
useSession
A function that intercepts incoming requests to implement logic like route protection or A/B testing