Installation
Quick Start
Next.js 16 renamed middleware to proxy.credGates works with both; only the file and export name differ. Create the file in your project root (or in src/, next to app/ or pages/):
- Next.js 16+ (proxy.ts)
- Next.js 14 and 15 (middleware.ts)
/api/* is evaluated before reaching your route handler. Wallets that fail the trust check receive a 402 or 403 response before your route runs, so your API handlers only see trusted traffic.
Upgrading to Next.js 16? Next’s codemod renames the file and export for you:
npx @next/codemod@canary middleware-to-proxy .Configuration
Wallet Address Extraction
By default the middleware checks:X-Wallet-Addressrequest header?wallet=query parameter
extractWallet:
Response Headers
Whenheaders: true (default), every evaluated request gets these headers set on the response, 402 and 403 denials included:
Read these in your API route handlers:
Route Matching
Thematcher option controls which routes are trust-gated. Routes that don’t match pass through without evaluation.
Also set
config.matcher in your proxy.ts (or middleware.ts) so Next.js only invokes credGates on matching routes. Without it, Next.js calls it on every request, including static files.Failure Responses
With
on402: 'deny' the 403 body is: