Next.js App Router API patterns — Route Handlers, Server Actions, middleware, validation, caching, error handling
92
90%
Does it follow best practices?
Impact
95%
1.58xAverage score across 5 eval scenarios
Passed
No known issues
Build a Next.js App Router application with a dashboard that has protected API endpoints. The dashboard shows analytics data that should only be accessible to authenticated users.
Requirements:
GET /api/dashboard/stats -- returns dashboard statistics (total users, total orders, revenue)GET /api/dashboard/orders -- returns recent orders with pagination (page, limit query params)GET /api/dashboard/orders/[id] -- returns a single order by IDPOST /api/dashboard/orders/[id]/notes -- add a note to an orderAll /api/dashboard/* endpoints require an Authorization: Bearer <token> header. If missing or invalid, return 401.
Use a simulated auth check: treat any token that starts with "valid_" as authentic.
Also create:
/dashboard that displays the statsUse in-memory storage with some seed data.
Produce:
middleware.ts for auth protectionapp/dashboard/page.tsx -- dashboard pagepackage.json with dependenciesYou may create additional files as needed.