Middleware
I have a dozen endpoints that all need login checks and request logging—where do I put that without copying it into every file?
/login is accidentally included in the auth matcher, the browser gets trapped in an infinite redirect loop.You can say this to an AI Agent
Ready to paste into Cursor, Claude Code, or CodexExtract a request-logging middleware and an auth middleware: run logging before auth, scope auth only to protected paths like `/api/orders` and `/dashboard`, and exclude `/login`, `/health`, and static assets. Verify that unauthenticated `/api/orders` returns 401, `/login` returns 200 without a redirect loop, and blocked requests still appear in logs.
