Next.js integration
Wrap existing App Router handlers with the server SDK and manage their protection in the dashboard.
Map your first route
Choose an authenticated JSON endpoint in Connect application. Map its method and full path, such as GET /api/customers/:id. The existing handler keeps its authentication, authorization and business logic. Use the Node.js runtime and dynamic execution for protected routes.
Download the personalized setup prompt for Codex/Cursor, or follow the manual examples below. Add TXNSHIELD_SECRET_KEY and TXNSHIELD_API_BASE_URL to server-only environment variables. Browser signals are optional; the browser SDK is not required for the new quick profiles.
Install
npm install @txnshield/sdk-node@0.6.0 server-onlylib/txnshield.ts · create the shared server client
import "server-only";
import { createTxnShieldNode } from "@txnshield/sdk-node";
export const shield = createTxnShieldNode({
secretKey: process.env.TXNSHIELD_SECRET_KEY!,
apiBaseUrl: process.env.TXNSHIELD_API_BASE_URL!,
});Your existing route.ts · wrap GET
import { shield } from "@/lib/txnshield";
// Reuse your application's verified server-side authentication helper.
import { getAuthenticatedUser } from "@/lib/app-auth";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
// Keep your original handler in this file, renamed existingGET.
// Its validation, authorization, business logic and Response stay unchanged.
export const GET = shield.route({
actor: async (request) => {
const user = await getAuthenticatedUser(request);
return { id: user?.id ?? "anonymous", authenticated: Boolean(user), roles: user?.roles ?? [] };
},
}, existingGET);Response behavior and scope
The adapter calls the existing handler only for allowed or unmapped requests. Deny returns 403, throttle 429, verification 409, missing authentication 401 and unavailable protection 503. Mapped responses are private/no-store. Keep the route dynamic so framework caching cannot skip evaluation.
Required redaction buffers structured JSON up to 1 MiB by default with a 5-second deadline. Unsupported, oversized or invalid responses return 503 without releasing their body. Preserve application authorization and configure paths such as data.email to match serialized JSON.
Apply the wrapper to every selected HTTP method. Next.js route parameters reach the original handler unchanged. Exports require the actual authorized count via context; verification requires backend-validated proof. Pages Router, Server Actions, Edge runtime and custom streaming responses use the advanced guides.
Verify
Test locally that allowed requests execute once and denied, throttled, challenged or unavailable evaluations never run business logic. Then send a real authenticated development request and refresh mapped-route status. A received evaluation confirms the connection; test handler and response behavior separately.
Next steps