0
Challenge · 32Mutations & Auth

proxy.ts (middleware replacement)

Securityused in ~70% of apps

Half the Next.js tutorials you have read are now wrong about one file. In v16 the request interceptor is no longer `middleware.ts` — it is `proxy.ts`, it exports `proxy`, and it runs on the Node runtime. Ship the old name to an interviewer and they will know exactly which year you stopped reading the changelog.

Core idea. `proxy.ts` is the single file that runs before every matched request reaches your routes and cache — perfect for cheap, optimistic redirects (logged-out user hits a protected URL → bounce to /login). It replaces `middleware.ts`: rename the file AND the exported function, runs on Node now, logic otherwise unchanged. It is a gate, never the lock.
Playground, this isn't a screenshot
myapp.com/

<Home />

Public page — anyone can open this, logged in or not.

You are logged out. Click a locked page and watch the guard redirect you.
route needs auth redirected to /login sent back to intended page
↑ play a little first, then dig in