+0
日增长
992
stars
292
forks
27
watchers
955
prs
358
issues
67
releases
README
!Auth0 SDK for React Single Page Applications
!Downloads
📚 Documentation - 🚀 Getting Started - 💻 API Reference - 💬 Feedback
Documentation
- Quickstart - our interactive guide for quickly adding login, logout and user information to a React app using Auth0.
- Sample App - a full-fledged React application integrated with Auth0.
- FAQs - frequently asked questions about the auth0-react SDK.
- Examples - code samples for common React authentication scenario's.
- Docs site - explore our docs site and learn more about Auth0.
Getting started
Installation
Using npm
bash
npm install @auth0/auth0-react
Using yarn
bash
yarn add @auth0/auth0-react
Configure Auth0
Create a Single Page Application in the Auth0 Dashboard.
If you're using an existing application, verify that you have configured the following settings in your Single Page Application:
- Click on the "Settings" tab of your application's page.
- Scroll down and click on the "Show Advanced Settings" link.
- Under "Advanced Settings", click on the "OAuth" tab.
- Ensure that "JsonWebToken Signature Algorithm" is set to RS256 and that "OIDC Conformant" is enabled.
Next, configure the following URLs for your application under the "Application URIs" section of the "Settings" page:
- Allowed Callback URLs: http://localhost:3000
- Allowed Logout URLs: http://localhost:3000
- Allowed Web Origins: http://localhost:3000
These URLs should reflect the origins that your application is running on. Allowed Callback URLs may also include a path, depending on where you're handling the callback.
Take note of the Client ID and Domain values under the "Basic Information" section. You'll need these values in the next step.
Configure the SDK
Configure the SDK by wrapping your application in Auth0Provider:
jsx
// src/index.js
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Auth0Provider } from '@auth0/auth0-react';
import App from './App';
const root = createRoot(document.getElementById('app'));
root.render(
);
Instructions for React
jsx
// src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Auth0Provider } from '@auth0/auth0-react';
import App from './App';
ReactDOM.render(
,
document.getElementById('app')
);
Use the useAuth0 hook in your components to access authentication state (isLoading, isAuthenticated and user) and authentication methods (loginWithRedirect and logout):
jsx
// src/App.js
import React from 'react';
import { useAuth0 } from '@auth0/auth0-react';
function App() {
const { isLoading, isAuthenticated, error, user, loginWithRedirect, logout } =
useAuth0();
if (isLoading) {
return Loading...;
}
if (error) {
return Oops... {error.message};
}
if (isAuthenticated) {
return (
Hello {user.name}{' '}
logout({ logoutParams: { returnTo: window.location.origin } })}
Log out
);
} else {
retTop issues
#929Users getting logged out with "Unsuccessful Refresh Token exchange, reused refresh token detected"19 comments · 2025-11-10#562Session not cleared if user uses Back after logout14 comments · 2023-08-24#1321Inability to capture errors that come from underlying auth0 spa js package0 comments · 2026-11-06
Discussions
#894Seeking Feedback: A New, Modern React Quickstart 🚀0 comments · 2025-09-16#843fetch multiple access tokens simultaneously5 comments · 2025-02-11
Latest release
v2.30.0 v2.30.0 2026-10-30Added - feat(myaccount): add getUserProfile and updateUserProfile methods \1315 (siddhikotak)