Skip to main content

Use AI to integrate Auth0

If you use an AI coding assistant like Claude Code, Cursor, or GitHub Copilot, you can add Auth0 authentication automatically in minutes using agent skills.Install:
Then ask your AI assistant:
Your AI assistant will automatically create your Auth0 application, fetch credentials, install @auth0/auth0-react, configure the Auth0Provider, and create all necessary components. Full agent skills documentation →
Prerequisites: Before you begin, ensure you have the following installed:Verify installation: node --version && npm --versionReact Version Compatibility: This quickstart works with React 18.x and newer.

Get Started

This quickstart demonstrates how to add Auth0 authentication to a React application. You’ll build a secure single-page app with login, logout, and user profile features using the Auth0 React SDK.
1

Create a new project

Create a new React project for this Quickstart
Open the project
2

Install the Auth0 React SDK

3

Setup your Auth0 App

Next up, you need to create a new app on your Auth0 tenant and add the environment variables to your project.You have three options to set up your Auth0 app: use the Quick Setup tool (recommended), run a CLI command, or configure manually via the Dashboard:
Verify your .env file exists: cat .env (Mac/Linux) or type .env (Windows)
4

Add the provider

src/main.tsx
5

Create Login, Logout and Profile Components

Create files
And add the following code snippets
7

Run your app

If port 5173 is in use, run: npm run dev -- --port 5174 and update your Auth0 app’s callback URLs to http://localhost:5174
CheckpointYou should now have a fully functional Auth0 login page running on your localhost

Advanced Usage

Use Auth0’s authentication state to protect specific routes in your application:
src/App.jsx
Configure your Auth0Provider to include an API audience and use the getAccessTokenSilently method:
src/main.jsx
Then make authenticated API calls:
src/components/ApiCall.jsx
Create reusable custom hooks for common authentication patterns:
src/hooks/useAuthenticatedUser.js
Usage in components:
src/components/UserDashboard.jsx