@didit-protocol/auth-react package gives a React application a DiditAuth provider, the useAuth and useUser hooks and ready-made SignIn, SignUp, SignedIn, SignedOut and UserButton components.
It is published on npm at version 0.3.0 and runs on the browser client from @didit-protocol/auth.
It needs React 18.2 or later, or React 19.
Use a Sandbox application while you build.
Every Sandbox application has Authentication turned on from the start.
A Live application turns Authentication on from the Products page of the console: see Prepare your application.
Using Next.js? Follow the Next.js quickstart instead: it keeps the session in
HttpOnly cookies.Install
Register your addresses
Copy your publishable key from Authentication > Developers in the console. Then register these in Authentication > Security and sessions > Redirect URLs and allowed origins:
A Sandbox application accepts
http:// on localhost, 127.0.0.1 and [::1], each port separately.
A Live application accepts https:// only.
Add sign-in
App.tsx
DiditAuth completes the redirect when the person comes back, restores the session after a reload and provides it to everything below it.
SignIn sends a signed-out visitor to your hosted sign-in page.
SignedIn and SignedOut render nothing while the session is still loading, so keep your own loading state with isLoaded.
Components
useAuth() returns isLoaded, isSignedIn, userId, sessionId, session, signIn, signUp, signOut, getToken, stepUp, handleStepUpCallback, reauthenticate, and the headless steps password, emailCode, phone, protection and mfa for your own screens.
useUser() returns { isLoaded, isSignedIn, user }, where user holds id, email, emailVerified, phone, vendorData, verifiedIdentity and organizations.
vendorData is the id that ties the person to their verifications and transactions: see keep one person across products.
Components follow the device’s light or dark setting.
Override the theme, accent and font with appearance={{ theme: "dark", brandColor: "#6B3CF6", fontFamily: "Inter" }}.
English, Spanish, French, German and Japanese are built in, and locale takes any BCP 47 tag.
Under a strict Content Security Policy, pass nonce for the one <style> element the provider renders.
Call your backend
getToken() returns a short-lived access token (five minutes) that refreshes shortly before it expires.
Send it as a Bearer token and verify it on your server with verifyToken from @didit-protocol/auth/server:
server.ts
verifyToken checks.