next-api-layerNext API Layer
DocumentationAPI ReferenceExamples
next-api-layerNext API Layer

Production-grade API layer for Next.js with external JWT backends.

Documentation

  • Introduction
  • Installation
  • Quick Start
  • API Reference

Resources

  • Examples
  • Proxy
  • API Client
  • AuthProvider

Community

  • GitHub
  • Issues
  • Discussions
  • Contact

© 2026 Next API Layer. All rights reserved.

Created by
Documentation

Getting Started

  • Introduction
  • Installation
  • Quick Start

Core Concepts

  • How It Works
  • Token Management
  • Guest Tokens

Configuration

  • Auth Proxy
  • Proxy Handler
  • API Client
  • Security
  • i18n Integration

Client Side

  • AuthProvider
  • useAuth Hook

API Reference

  • API Reference
  • Types

Examples

  • Examples
  • Authentication Patterns
  • Role-Based Access
  • API Routes
  • Forms
  • Data Fetching
Changelog

Getting Started

  • Introduction
  • Installation
  • Quick Start

Core Concepts

  • How It Works
  • Token Management
  • Guest Tokens

Configuration

  • Auth Proxy
  • Proxy Handler
  • API Client
  • Security
  • i18n Integration

Client Side

  • AuthProvider
  • useAuth Hook

API Reference

  • API Reference
  • Types

Examples

  • Examples
  • Authentication Patterns
  • Role-Based Access
  • API Routes
  • Forms
  • Data Fetching
Changelog

Proxy Handler

The createProxyHandler function creates a simple API route handler that proxies requests directly to your backend without the full middleware pipeline.

When to Use#

Use createProxyHandler when you need:

  • Simple request proxying without token validation
  • Direct backend access with optional auth
  • Custom API routes that bypass middleware
  • Public endpoints that don't need authentication

For full authentication middleware with token refresh and validation, use createAuthProxy instead.

Basic Setup#

TypeScript
Loading...

Configuration#

ProxyHandlerConfig#

OptionTypeDefaultDescription
apiBaseUrlstringRequiredBase URL of your backend API
userCookieNamestring"auth_token"Cookie name for user auth token
guestCookieNamestring"guest_token"Cookie name for guest auth token
skipAuthByDefaultbooleanfalseSkip auth for all requests by default
publicEndpointsstring[][]Endpoints that never include auth token (glob patterns)
forwardHeadersstring[]["content-type", "accept", ...]Headers to forward from client request
excludeHeadersstring[]["host", "connection", "cookie"]Headers to exclude from forwarding
transformRequest(req, headers) => Headers-Custom request transformer
transformResponse(response) => Response-Custom response transformer

Public Endpoints#

Define endpoints that should never include authentication tokens:

TypeScript
Loading...

Glob Pattern Support#

  • * - Matches any characters except /
  • ** - Matches any characters including /
  • Exact string - Exact match only

Skip Auth Header#

Individual requests can skip auth by sending the X-Skip-Auth header:

TypeScript
Loading...

Custom Transformers#

Request Transformer#

Modify headers before sending to backend:

TypeScript
Loading...

Response Transformer#

Modify response before sending to client:

TypeScript
Loading...

Comparison with createAuthProxy#

FeaturecreateProxyHandlercreateAuthProxy
Token ValidationNoYes
Token RefreshNoYes
Guest Token CreationNoYes
CSRF ProtectionNoYes
Rate LimitingNoYes
Route ProtectionBasic (publicEndpoints)Full (protectedRoutes, authRoutes)
Custom TransformersYesLimited
Use CaseSimple proxying, public APIsFull authentication flow

Full Example#

TypeScript
Loading...

TypeScript#

TypeScript
Loading...