Skip to main content

AI Prompt

Using AI to integrate Auth0? Add this prompt to Cursor, Windsurf, Copilot, Claude Code or your favourite AI-powered IDE to speed up development.
Prerequisites: Before you begin, ensure you have the following installed:React 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 can choose to do this automatically by running a CLI command or do it manually via the Dashboard:
Run the following shell command on your project’s root directory to create an Auth0 app and generate a .env file:
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

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