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

Quick Start

This guide will get you up and running with next-api-layer in under 5 minutes.

1. Create the Proxy Configuration#

Create a proxy.ts file in your src directory:

TypeScript
Loading...

2. Create the Catch-All API Route#

Create the API route that will handle all requests:

TypeScript
Loading...

3. Make API Calls#

Now you can use the api client anywhere in your app:

TypeScript
Loading...
TypeScript
Loading...

4. Add Client-Side Auth (Optional)#

For client-side authentication state, add the AuthProvider:

TypeScript
Loading...

Then use the useAuth hook:

TypeScript
Loading...

What's Happening?#

When you make a request through the proxy:

  1. Token Check: The proxy checks for a valid JWT token in cookies
  2. Validation: If expired, it automatically refreshes the token
  3. Guest Fallback: If no token exists and guest is enabled, it creates a guest token
  4. Request Forward: The request is forwarded to your backend with the token
  5. Response Security: The response is sanitized for XSS protection
  6. Cookie Update: If token was refreshed, new cookies are set

All of this happens automatically. You just write api.get('endpoint').

Next Steps#

  • How It Works - Deep dive into the architecture
  • Auth Proxy Configuration - Customize the proxy
  • Security Features - CSRF, rate limiting, and more