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

Auth Proxy Configuration

The createAuthProxy function creates a Next.js proxy that handles all authentication logic. This page covers all configuration options.

Basic Setup#

TypeScript
Loading...

Configuration Options#

apiBaseUrl#

Required - Your backend API base URL.

TypeScript
Loading...

cookies#

Required - Cookie configuration for token storage.

TypeScript
Loading...

endpoints#

Backend endpoints for auth operations. All paths are relative to apiBaseUrl.

TypeScript
Loading...

guestToken#

Configure guest token behavior.

TypeScript
Loading...

access#

Route access control configuration.

TypeScript
Loading...

i18n#

Internationalization support. Extracts locale from URL path and sets x-locale header for downstream route handlers.

TypeScript
Loading...

How it works:

  1. User visits /tr/blog
  2. Proxy extracts tr from the first path segment
  3. Sets x-locale: tr header on the request
  4. Route handlers can read this header
  5. API client automatically appends ?lang=tr to backend requests

See the i18n documentation for full setup guide.

excludedPaths#

Paths to skip proxy entirely.

TypeScript
Loading...

blockBrowserApiAccess#

Block direct browser access to API routes.

TypeScript
Loading...

When enabled, requests with Accept: text/html to /api/* are redirected to /.

responseMappers#

Custom parsers for different backend response formats.

TypeScript
Loading...

csrf#

CSRF protection configuration.

TypeScript
Loading...

rateLimit#

Rate limiting configuration.

TypeScript
Loading...

audit#

Audit logging configuration.

TypeScript
Loading...

onError#

Global error handler.

TypeScript
Loading...

beforeAuth#

Hook that runs before auth validation.

TypeScript
Loading...

afterAuth#

Hook that runs after auth validation.

TypeScript
Loading...

Full Example#

TypeScript
Loading...