React Quickstart
Use this guide to add Choreo Identity & Access Management authentication to a React application using the @thunderid/react SDK.
What You Will Learn
- Create a new React app using Vite
- Install the
@thunderid/reactpackage - Build with Choreo Identity & Access Management prebuilt components
Prerequisites
- About 15 minutes
- Node.js installed on your system
- npm, yarn, or pnpm
- Your preferred code editor
Create an Application
- Sign in to the Console at https://console.cloud.choreolabs.com/iam/. Select your project in the project switcher in the header.
- Navigate to Applications.
- Click Add application.
- From the Choose a type page, select React.
- Enter a name (e.g.
My React App). - Click Create.
- Select how you want to sign in users (e.g., email/password, social login, etc.).
- Select Theme settings and other options.
- In the Configuration step, click on the banner to add Vite's development server URL to the list of Authorized redirect URIs & CORS allowed origins. The default is
http://localhost:5173(adjust the port if your dev server uses a different one).
Copy the Client ID from the General tab. You'll need it when configuring the SDK.
Code in this guide uses https://<DATA_PLANE_URL> for your environment's data plane URL, where users sign in and tokens are issued. Replace it with the URL on the environment's Endpoints page. To open it, select your project, go to Deployment pipeline, and click Open environment on the environment's card. See Control Plane and Data Plane URLs.
Saving a change does not make it live. You author in the control plane, and your users sign in on a separate data plane, so a change takes effect in an environment only after you deploy it. Go to Deploy, deploy the latest version to your first environment, then promote it to the next environment when you are ready.
Auto-sync deploys saved changes to your first environment within seconds. Turning it on is your choice, per project. See Deploy a Version, or learn why you deploy and how auto-sync works.
Create a React App
Create your new React app using Vite:
- npm
- Yarn
- pnpm
- Bun
- Deno
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
yarn create vite my-react-app --template react
cd my-react-app
yarn install
pnpm create vite my-react-app --template react
cd my-react-app
pnpm install
bun create vite my-react-app --template react
cd my-react-app
bun install
deno run -A npm:create-vite@latest my-react-app --template react
cd my-react-app
deno install
Install @thunderid/react
Install the Choreo Identity & Access Management React SDK in your project:
- npm
- Yarn
- pnpm
- Bun
- Deno
npm install @thunderid/react
yarn add @thunderid/react
pnpm add @thunderid/react
bun add @thunderid/react
deno add npm:@thunderid/react
Add ThunderIDProvider to Your App
The <ThunderIDProvider /> serves as a context provider for the SDK. Integrate it by wrapping your root component.
Update the main.jsx file with the following:
Replace <your-client-id> with the Client ID you obtained when creating the application in Choreo Identity & Access Management.
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { ThunderIDProvider } from '@thunderid/react'
import App from "./App.jsx"
import './index.css'
createRoot(document.getElementById('root')).render(
<StrictMode>
<ThunderIDProvider
clientId="<your-client-id>"
baseUrl="https://<DATA_PLANE_URL>"
>
<App />
</ThunderIDProvider>
</StrictMode>
)
Configuration Parameters
| Parameter | Description |
|---|---|
clientId | The Client ID from your Choreo Identity & Access Management application |
baseUrl | Your Choreo Identity & Access Management instance URL (e.g., https://<DATA_PLANE_URL>) |
Build with Choreo Identity & Access Management Components
You can control which content signed-in and signed-out users can see with the prebuilt control components. Replace the content of App.jsx with the following, which uses these components:
<SignedIn>: Children of this component can only be seen while signed in.<SignedOut>: Children of this component can only be seen while signed out.<UserDropdown />: Shows the signed-in user's avatar. Selecting it opens a dropdown menu with account management options.<SignInButton />: An unstyled component that links to the Choreo Identity & Access Management-hosted sign-in page.
import {
SignedIn,
SignedOut,
SignInButton,
SignOutButton,
Loading,
UserDropdown
} from '@thunderid/react'
import './App.css'
function App() {
return (
<>
<section id="center">
<SignedIn>
<UserDropdown />
</SignedIn>
<SignedOut>
<SignInButton>Sign In</SignInButton>
</SignedOut>
</section>
</>
)
}
export default App
Run Your App
Start the development server:
- npm
- Yarn
- pnpm
- Bun
- Deno
npm run dev
yarn dev
pnpm run dev
bun run dev
deno task dev
You'll need a user to sign in with. If you haven't created one yet, open https://console.cloud.choreolabs.com/iam/, navigate to Users, and add a test user with an email and password.
Visit your app at 🌐 http://localhost:5173
You should see the <SignInButton />. Click it, you'll be redirected to the Choreo Identity & Access Management-hosted sign-in page. Login with your test user and you'll land back in your app with the user profile displayed.
Need single logout or more secure token storage?
This quickstart runs entirely in the browser, so the SDK keeps your tokens in browser storage, where any script on the page can read them. It also can't support single logout: if users sign in to this app and another app through single sign-on, signing out of the other app leaves them signed in here until their tokens stop working. If either matters for your app, pick one of these setups.
Build with Next.js (Recommended)
Still React, with a server side. The Next.js SDK signs users in on the server and receives back-channel logout.
- Tokens in an HttpOnly cookie that scripts cannot read
- Single logout through back-channel logout
Add a Backend for Frontend (BFF) (Can't migrate?)
Keep this React app and add a small server that signs users in and holds the tokens. The refresh token stays on the server, and the browser gets an HttpOnly session cookie.
- No rewrite of your React code
- Single logout through the BFF
React and Express BFF sample · How to set up a BFF
Run the Sample App
The React sample is a working version of the app this guide builds. To run it instead of building the app yourself:
-
Download the sample from its releases and open its folder.
-
Create
.envin the sample's folder with your application's values:.envVITE_THUNDERID_BASE_URL=https://<DATA_PLANE_URL>VITE_THUNDERID_CLIENT_ID=<your-client-id> -
Install the dependencies and start the app:
npm installnpm run dev -
Open http://localhost:5173 and sign in.
What's Next
- Upgrade the sign-in flow: Add MFA, passkeys, or social login to your flow, no app code changes required.
- React SDK Reference: Explore the full API reference for the React SDK.
Was this page helpful?