This guide demonstrates how to integrate Auth0, add authentication, and display user profile information in a Single-Page Application (SPA) that uses React, using the Auth0 React SDK.
Use this file to discover all available pages before exploring further.
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:
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:
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.
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:
Quick Setup (recommended)
CLI
Dashboard
Create an Auth0 App and copy the pre-filled .env file with the right configuration values.
Run the following command in your project’s root directory to create an Auth0 app and generate a .env file:
# Install Auth0 CLI (if not already installed)brew tap auth0/auth0-cli && brew install auth0# Set up Auth0 app and generate .env fileauth0 qs setup --type vite -n "My App" -p 5173
This command will:
Check if you’re authenticated (and prompt for login if needed)
Create an Auth0 Single Page Application configured for http://localhost:5173
Generate a .env file with VITE_AUTH0_DOMAIN and VITE_AUTH0_CLIENT_ID
Before you start, create a .env file on your project’s root directory
Click on Applications > Applications > Create Application
In the popup, enter a name for your app, select Single Page Web Application as the app type and click Create
Switch to the Settings tab on the Application Details page
Replace YOUR_AUTH0_APP_DOMAIN and YOUR_AUTH0_APP_CLIENT_ID on the .env file with the Domain and Client ID values from the dashboard
Finally, on the Settings tab of your Application Details page, configure the following URLs:Allowed Callback URLs:
http://localhost:5173
Allowed Logout URLs:
http://localhost:5173
Allowed Web Origins:
http://localhost:5173
Allowed Callback URLs are a critical security measure to ensure users are safely returned to your application after authentication. Without a matching URL, the login process will fail, and users will be blocked by an Auth0 error page instead of accessing your app.Allowed Logout URLs are essential for providing a seamless user experience upon signing out. Without a matching URL, users will not be redirected back to your application after logout and will instead be left on a generic Auth0 page.Allowed Web Origins is critical for silent authentication. Without it, users will be logged out when they refresh the page or return to your app later.
Verify your .env file exists: cat .env (Mac/Linux) or type .env (Windows)
4
Add the provider
src/main.tsx
import { StrictMode } from 'react';import { createRoot } from 'react-dom/client';import './index.css'; // Importing the main CSS fileimport App from './App.tsx';import { Auth0Provider } from '@auth0/auth0-react';createRoot(document.getElementById('root')!).render( <StrictMode> <Auth0Provider domain={import.meta.env.VITE_AUTH0_DOMAIN} clientId={import.meta.env.VITE_AUTH0_CLIENT_ID} authorizationParams={{ redirect_uri: window.location.origin }} > <App /> </Auth0Provider> </StrictMode>);