Skip to main content
The client API provides React hooks, components, and utilities for implementing Auth0 authentication in Next.js client components and pages.

Installation

Available Exports

The client API is available from the main package export:

Core Features

Hooks

useUser

React hook to access the authenticated user’s profile and session state

Helpers

getAccessToken

Fetch access tokens for calling external APIs from client components

withPageAuthRequired

Higher-order component to protect client-side rendered pages

Providers

Auth0Provider

Context provider for optimizing user data fetching with SWR

Quick Start

1. Wrap Your App with Auth0Provider

For optimal performance, wrap your application with Auth0Provider in your root layout:
app/layout.tsx

2. Access User Data

Use the useUser hook in any client component:
app/profile/page.tsx

3. Fetch Access Tokens

Call external APIs with access tokens:
app/components/data-fetcher.tsx

4. Protect Client Pages

Use withPageAuthRequired to protect client-side rendered pages:
app/dashboard/page.tsx

Client vs Server API

The Auth0 Next.js SDK provides both client-side and server-side APIs:

Environment Variables

You can customize the API routes used by client utilities:
.env.local

TypeScript Support

All client exports include full TypeScript type definitions:

Next Steps

useUser Hook

Learn how to access user data in client components

Get Access Tokens

Fetch tokens for calling external APIs

Protect Pages

Secure client-side rendered pages

Server API

Explore server-side authentication utilities