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 withAuth0Provider in your root layout:
app/layout.tsx
2. Access User Data
Use theuseUser 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
UsewithPageAuthRequired 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:| Feature | Client API | Server API |
|---|---|---|
| Import Path | @auth0/nextjs-auth0 | @auth0/nextjs-auth0/server |
| Use Case | Client components, browser | Server components, API routes, middleware |
| User Access | useUser() hook | getSession() method |
| Token Fetching | getAccessToken() (calls /auth/access-token) | getAccessToken() (direct token access) |
| Page Protection | withPageAuthRequired (CSR) | withPageAuthRequired (SSR) |
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