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

Guest Tokens

Guest tokens provide anonymous user sessions, enabling features like shopping carts, wishlists, or personalized content without requiring login.

Overview#

Guest tokens work transparently alongside user tokens:

  • Automatically created when no auth token exists
  • Stored in a separate cookie from user tokens
  • Seamlessly upgraded to user tokens on login
  • Configurable credentials for your backend

Configuration#

Enable guest tokens in your proxy:

TypeScript
Loading...

Backend Setup#

Your backend needs a guest authentication endpoint:

Endpoint#

Loading...

Expected Response#

JSON
Loading...

Custom Response Format#

If your backend uses a different format:

TypeScript
Loading...

How Guest Tokens Work#

Creation Flow#

Loading...

Token Priority#

When both tokens exist:

TypeScript
Loading...

On login, the guest cookie is automatically cleared.

Detecting Guest Users#

In Proxy (afterAuth)#

TypeScript
Loading...

In Server Components#

TypeScript
Loading...

In Client Components#

TypeScript
Loading...

Guest to User Upgrade#

When a guest user logs in:

TypeScript
Loading...

Backend Considerations#

Your backend should handle guest-to-user data migration:

PHP
Loading...

Guest Token Expiration#

Guest tokens typically have shorter lifespans:

TypeScript
Loading...

When expired, a new guest token is automatically created.

Use Cases#

Shopping Cart#

TypeScript
Loading...

Content Personalization#

TypeScript
Loading...

Rate Limiting by Session#

TypeScript
Loading...

Disabling Guest Tokens#

For apps that require login:

TypeScript
Loading...

Security Considerations#

Separate Credentials#

Always use dedicated guest credentials:

.env
Loading...

Limited Permissions#

Your backend should give guest tokens minimal permissions:

PHP
Loading...

Don't Store Sensitive Data#

Guest sessions should not store:

  • Personal information
  • Payment details
  • Sensitive preferences

Instead, require login for sensitive operations.