Skip to main content

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/):
Proxy runs on the Node.js runtime.
Every request to /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:
  1. X-Wallet-Address request header
  2. ?wallet= query parameter
Override with extractWallet:

Response Headers

When headers: 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

The matcher 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: