API reference
Full referenceuseThunderID()The
useThunderID hook provides access to the ThunderID authentication context in React applications. It allows you to retrieve authentication state, user information, and other context values managed by the ThunderIDProvider.isSignedInbooleanWhether the user is currently signed in
userUser \The authenticated user object, or `null` if not signed in
signIn() => PromiseInitiates the sign-in flow
signOut() => PromiseInitiates the sign-out flow
loadingbooleanIndicates if an authentication operation is in progress
errorError \The last error encountered during authentication, if any
currentOrganizationUnitCurrentOrganizationUnit | nullThe organization unit the session was issued for, read from its `ouId`, `ouHandle`, and `ouName` claims for display only, or `null`
getCurrentOrganizationUnit() => Promise<CurrentOrganizationUnit | null>Reads the current organization unit from the session's claims
switchOrganizationUnit(organizationUnitId: string, options?: SwitchOrganizationUnitOptions) => Promise<User | undefined>Signs in again bounded to another organization unit. A failed switch keeps the previous session, unless a backend reports that its session has ended, and rejects with a code from `OrganizationUnitSwitchErrorCodes`
import { useThunderID } from '@thunderid/react'function MyComponent() {const { isSignedIn, user, signIn, signOut } = useThunderID()return (<div>{isSignedIn ? (<><p>Welcome, {user?.displayName}!</p><button onClick={() => signOut()}>Sign Out</button></>) : (<button onClick={() => signIn()}>Sign In</button>)}</div>)}export default MyComponent
Get started
Provider, session, and a protected route, start to finish.
Connect your application
~5 minGetting started / Connect your application / React
The quickstart is maintained alongside the rest of the getting-started guides so it stays in step with the platform. This page covers the package itself: its API surface, guides, and compatibility.
Guides
Task-focused walkthroughs maintained alongside the SDK.
Protecting routes
Guard a route tree so unauthenticated visitors are sent through sign-in, covering React Router, TanStack Router, and a hand-rolled guard.
20 min readAccessing protected APIs
Attach an access token to requests against your own resource server.
8 min readUsing a Backend for Frontend (BFF)
Keep the tokens on a server of your own and support single logout, with an Express BFF that signs users in for your React app.
15 min read