Skip to main content

Installation

Install the React components, add the provider once, and add the page that finishes sign-in.

Install​

npm install @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.

src/main.tsx
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.

src/pages/AuthCallback.tsx
import { AuthCallback } from '@lumoauth/react';

export default function AuthCallbackPage() {
return <AuthCallback afterSignInUrl="/dashboard" />;
}

Provider props​

PropTypeDefaultDescription
clientIdrequiredstringThe client ID of your application.
domainstringThe LumoAuth host, for example https://app.lumoauth.dev. Required unless customDomain is set.
orgIdstringYour organization ID, for example acme-corp. Required on the LumoAuth host.
customDomainstringYour 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.
redirectUristringThe address of your callback page. Required in PKCE mode.
scopestring'openid profile email'Scopes to request, separated by spaces. Add abac:read for useAbac and <Protect abac>, and authz:read to list permissions.
afterSignInUrlstringWhere to go after sign-in. Defaults to the current page.
afterSignUpUrlstringWhere to go after sign-up.
afterSignOutUrlstring'/'Where to go after sign-out.
storageTokenStoragesessionStorageWhere 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.
crossTabbooleantrueShare 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.