How this works panel
A side panel that shows the requests of the current flow, the tokens in them, and the docs page for each step.
Every application in this catalog explains itself with this panel. A visitor sees the protocol while they use the product: each request, its answer, the token that came back, and the docs page of the step.
Installation
- CLI
- Manual
The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.
- pnpm
- npm
- yarn
- bun
pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/how-this-works.json
npx shadcn@latest add https://examples.lumoauth.dev/r/how-this-works.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/how-this-works.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/how-this-works.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge buttonInstall the packages.
npm install lucide-reactAdd the pattern Token inspector, which this one uses.
Copy the code into your project.
components/how-this-works.tsx'use client';import * as React from 'react';import { BookOpen, Check, CircleDashed, Loader2, PanelRightClose, PanelRightOpen, X } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { TokenInspector } from '@/components/token-inspector';import { cn } from '@/lib/utils';export interface FlowStep {id: string;/** What happens, in plain words: "The agent asks for a token for this server". */title: string;state: 'pending' | 'active' | 'done' | 'failed';/** The request of the step, for example `{ method: 'POST', url: '/oauth/token' }`. */request?: { method: string; url: string };/** The HTTP status of the answer. */status?: number;/** One or two sentences on what LumoAuth did. */note?: string;/** The refusal, for a step that failed. */error?: string;/** A token that the step returned. It is shown decoded. */token?: string;/** The docs page of this step. */docsHref?: string;}export interface HowThisWorksProps {/** The steps of the flow, in order. Record them where your app makes its requests. */steps: FlowStep[];title?: string;defaultOpen?: boolean;className?: string;}const STATE = {pending: { icon: CircleDashed, tone: 'text-muted-foreground' },active: { icon: Loader2, tone: 'text-foreground' },done: { icon: Check, tone: 'text-emerald-700 dark:text-emerald-400' },failed: { icon: X, tone: 'text-red-700 dark:text-red-400' },} as const;export function HowThisWorks({ steps, title = 'How this works', defaultOpen = true, className }: HowThisWorksProps) {const [open, setOpen] = React.useState(defaultOpen);const [shown, setShown] = React.useState<string | null>(null);if (!open) {return (<Button variant="outline" size="sm" onClick={() => setOpen(true)} className={className}><PanelRightOpen aria-hidden="true" />{title}</Button>);}return (<aside className={cn('w-full max-w-lg rounded-xl border bg-card text-sm text-card-foreground shadow-sm', className)} aria-label={title}><header className="flex items-center justify-between gap-2 border-b px-4 py-2.5"><h2 className="font-semibold">{title}</h2><Button variant="ghost" size="icon" className="size-7" onClick={() => setOpen(false)} aria-label="Hide the panel"><PanelRightClose aria-hidden="true" /></Button></header><ol className="grid">{steps.map((step, index) => {const { icon: Icon, tone } = STATE[step.state];const expanded = shown === step.id;return (<li key={step.id} className={cn('grid gap-2 border-b px-4 py-3 last:border-b-0', step.state === 'pending' && 'opacity-60')}><div className="flex items-start gap-3"><span className={cn('mt-0.5 flex size-5 shrink-0 items-center justify-center', tone)}><Icon className={cn('size-4', step.state === 'active' && 'animate-spin')} aria-hidden="true" /></span><div className="grid min-w-0 flex-1 gap-1"><p className="font-medium"><span className="mr-1.5 text-muted-foreground tabular-nums">{index + 1}.</span>{step.title}</p>{step.request && (<p className="flex flex-wrap items-center gap-1.5 font-mono text-xs"><Badge variant="secondary" className="font-mono font-normal">{step.request.method}</Badge><span className="min-w-0 break-all text-muted-foreground">{step.request.url}</span>{step.status !== undefined && (<span className={cn('tabular-nums', step.status >= 400 ? 'text-red-700 dark:text-red-400' : 'text-emerald-700 dark:text-emerald-400')}>{step.status}</span>)}</p>)}{step.note && <p className="text-muted-foreground">{step.note}</p>}{step.error && <p className="text-red-700 dark:text-red-400">{step.error}</p>}<div className="flex flex-wrap gap-x-4 gap-y-1 empty:hidden">{step.token && (<buttontype="button"aria-expanded={expanded}onClick={() => setShown(expanded ? null : step.id)}className="text-xs font-medium underline underline-offset-4 outline-none hover:text-foreground focus-visible:text-foreground">{expanded ? 'Hide the token' : 'Show the token'}</button>)}{step.docsHref && (<a href={step.docsHref} className="inline-flex items-center gap-1 text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground"><BookOpen className="size-3.5" aria-hidden="true" />Docs</a>)}</div></div></div>{expanded && step.token && <TokenInspector token={step.token} className="max-w-none" />}</li>);})}</ol></aside>);}Change the import paths if your project keeps its components in another place.
Usage
Record a step wherever your app makes a request, and give the list to the panel.
'use client';
import * as React from 'react';
import { HowThisWorks, type FlowStep } from '@/components/how-this-works';
const FlowContext = React.createContext<(step: FlowStep) => void>(() => {});
export const useRecordStep = () => React.useContext(FlowContext);
export function Explain({ children }: { children: React.ReactNode }) {
const [steps, setSteps] = React.useState<FlowStep[]>([]);
// A step with a known id replaces the earlier one: pending, then done.
const record = React.useCallback((step: FlowStep) => {
setSteps((list) => (list.some((s) => s.id === step.id) ? list.map((s) => (s.id === step.id ? step : s)) : [...list, step]));
}, []);
return (
<FlowContext.Provider value={record}>
{children}
<HowThisWorks steps={steps} />
</FlowContext.Provider>
);
}
The panel shows tokens. Use it in a demo or in a tool for developers, not in a product that real people sign in to.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| The steps | Your own app: record each request where you make it |
| A token of a step | The answer of the token endpoint. The token inspector decodes it. |
| The docs link of a step | A page of docs.lumoauth.dev |
States
- Closed. The panel is a button until the reader opens it.
- A step that failed shows the refusal in plain words (step 4 of the first preview).
- A step that runs and steps that have not started (steps 5 and 6).
Props
| Prop | Type | Default | Description |
|---|---|---|---|
stepsrequired | FlowStep[] | The steps of the flow, in order. | |
title | string | 'How this works' | The title of the panel. |
defaultOpen | boolean | true | Open the panel at first. |
className | string | Class name for the panel. |
FlowStep
| Option | Type | Description |
|---|---|---|
idrequired | string | An ID for the step. |
titlerequired | string | What happens, in plain words. |
staterequired | 'pending' | 'active' | 'done' | 'failed' | The state of the step. |
request | { method: string; url: string } | The request of the step. |
status | number | The HTTP status of the answer. |
note | string | One or two sentences on what LumoAuth did. |
error | string | The refusal, for a step that failed. |
token | string | A token that the step returned. It is shown decoded. |
docsHref | string | The docs page of this step. |