auth0 /auth0-react

Auth0 SDK for React Single Page Applications (SPA)

★ 992⑂ 292👁 27⑃ 955● 358▤ 67
TypeScriptMITCreated 2020-04-23
More from this author
Download: v2.30.0v2.30.0 ↓2.30.02026-10-30
+0
Daily
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 {
    ret

Top issues

Discussions

Latest release

v2.30.0 v2.30.0 2026-10-30
Added
- feat(myaccount): add getUserProfile and updateUserProfile methods \1315 (siddhikotak)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON