What you’ll learn
- Obtain tokens: Authenticate users and retrieve ID and access tokens from Auth0.
- Call protected APIs: Use those tokens to call secured endpoints (e.g. user profile or custom APIs).
- Display user data: Pass the returned information into your AI agent or app to personalize the experience.
Before you start
Before you start
Before getting started, make sure you have completed the following steps:
1
Create an Auth0 Account
To continue with this quickstart, you need to have an Auth0 account.
2
Create an Auth0 Application
Go to your Auth0 Dashboard to create a new Auth0 Application.
- Navigate to Applications > Applications in the left sidebar.
- Click the Create Application button in the top right.
- In the pop-up select Regular Web Applications and click Create.
- Once the Application is created, switch to the Settings tab.
- Scroll down to the Application URIs section.
- Set Allowed Callback URLs as:
http://localhost:3000/auth/callback - Set Allowed Logout URLs as:
http://localhost:3000 - Click Save in the bottom right to save your changes.
3
OpenAI Platform
Set up an OpenAI account and API key.
Next.js
FastAPI
Getting started using AI
To get started quickly:Then, integrate Auth0 AI docs into your preferred AI tool:
- VS Code
- Cursor
- Claude Code
- Claude
or Follow manual steps
1
Install Auth0 Next.js SDK
2
Add log in to your application
Secure your application using the Auth0 Next.js SDK.Access your The Auth0 client provides methods for handling authentication, sessions, and user data.
Create your environment file
In the root directory of your project, create or add the following content to your.env.local file:.env.local
AUTH0_DOMAIN, AUTH0_CLIENT_ID, and AUTH0_CLIENT_SECRET by viewing the Auth0 Application that you created in the Auth0 Dashboard and navigating to the Basic Information section at the top of the Settings tab.
Copy each value to the matching setting.Next, run this command to generate a random 32 byte value and copy it to the AUTH0_SECRET field.generate random 32 byte value
Create the Auth0 client
Create a new file in thesrc/lib directory and name it auth0.ts. Add the following code to create a new Auth0 client:src/lib/auth0.ts
Add the authentication middleware
The middleware intercepts incoming requests and applies Auth0’s authentication logic. Create a new file in thesrc directory and name it middleware.ts or update your existing middleware file. Add the following code to the file:src/middleware.ts
Add Log in and Sign up buttons
Use the following code example to check if the user is signed in or not: It will display the Sign up or Log in buttons without a user session. If a user session exists, the app displays a welcome message with the user’s name.src/app/page.tsx
3
Run your application
Start your app, typically with this command:Visit your app in the browser, typically at 
Sign up to your application to create a new user account. You will then see a welcome message with your user name. You can sign in with that account on future visits.
http://localhost:3000.You will see:
