Installation
Install the React components, add the provider once, and add the page that finishes sign-in.
Install
- npm
- pnpm
- Yarn
- Bun
npm install @lumoauth/react
pnpm add @lumoauth/react
yarn add @lumoauth/react
bun add @lumoauth/react
The package needs React 18 or later. It adds its own styles when the provider mounts, so there is no CSS file to import.
Add the provider
Wrap your app in LumoAuthProvider once. Every component and hook on this site reads its state from that provider.
import { LumoAuthProvider } from '@lumoauth/react';
root.render(
<LumoAuthProvider
domain="https://app.lumoauth.dev"
orgId="acme-corp"
clientId="YOUR_CLIENT_ID"
redirectUri="http://localhost:3000/auth/callback"
>
<App />
</LumoAuthProvider>,
);
The client ID comes from the application that you create in the portal. Add the redirect URI to that application's list of allowed redirect URIs.
Add the callback page
After sign-in on the hosted page, the browser returns to your redirect URI. AuthCallback finishes the sign-in on that page.
import { AuthCallback } from '@lumoauth/react';
export default function AuthCallbackPage() {
return <AuthCallback afterSignInUrl="/dashboard" />;
}
Provider props
| Prop | Type | Default | Description |
|---|---|---|---|
clientIdrequired | string | The client ID of your application. | |
domain | string | The LumoAuth host, for example https://app.lumoauth.dev. Required unless customDomain is set. | |
orgId | string | Your organization ID, for example acme-corp. Required on the LumoAuth host. | |
customDomain | string | Your organization's custom domain, for example auth.acme.com. When it is set, sign-in, sign-out, the hosted pages and every API call use it, and domain is not used. | |
authStrategy | 'pkce' | 'password' | 'pkce' | pkce sends the person to the hosted sign-in page (authorization code with PKCE). password shows a form in your app that calls the OAuth password grant, which LumoAuth does not offer: keep the default. |
redirectUri | string | The address of your callback page. Required in PKCE mode. | |
scope | string | 'openid profile email' | Scopes to request, separated by spaces. Add abac:read for useAbac and <Protect abac>, and authz:read to list permissions. |
afterSignInUrl | string | Where to go after sign-in. Defaults to the current page. | |
afterSignUpUrl | string | Where to go after sign-up. | |
afterSignOutUrl | string | '/' | Where to go after sign-out. |
storage | TokenStorage | sessionStorage | Where tokens are kept. Import an adapter from @lumoauth/client: sessionStorageAdapter, localStorageAdapter, memoryStorageAdapter or cookieStorageAdapter. The cookie adapter reads the session from a same-origin route of your own server (default /auth/session), which must answer with the access token as JSON. See the recipe Choose where tokens are stored. |
crossTab | boolean | true | Share the session between browser tabs. One tab refreshes the token and sends the new tokens to the others on a BroadcastChannel, which every script of the same origin can read. |
Next.js
@lumoauth/nextjs exports the same components and adds a provider, a route handler and server helpers that keep tokens in an httpOnly cookie. See the Next.js starter.