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

useAuth Hook

The useAuth hook provides access to authentication state and actions from any component within the AuthProvider.

Basic Usage#

TSX
Loading...

Return Values#

user#

The current user object, or null if not authenticated.

TSX
Loading...

isAuthenticated#

Boolean indicating if user is authenticated (non-guest).

TSX
Loading...

isGuest#

Boolean indicating if current session is a guest.

TSX
Loading...

isLoading#

Boolean indicating if auth state is being fetched.

TSX
Loading...

error#

Error object if authentication failed.

TSX
Loading...

login#

Function to trigger login redirect or modal.

TSX
Loading...

logout#

Function to log out the user.

TSX
Loading...

mutate#

SWR mutate function to manually revalidate auth state.

TSX
Loading...

loginWithCredentials#

Function to log in with email/password.

TSX
Loading...

Examples#

Navigation with Auth State#

TSX
Loading...

Protected Component#

TSX
Loading...

Role-Based Access#

TSX
Loading...

Guest Upgrade Prompt#

TSX
Loading...

Login Form#

TSX
Loading...

Logout with Confirmation#

TSX
Loading...

TypeScript#

Custom User Type#

TSX
Loading...

Full Return Type#

TypeScript
Loading...

Requirements#

The useAuth hook must be used within an AuthProvider:

TSX
Loading...