Skip to main content

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.

PatternReadyView source
Works with
Reactshadcn/ui
Runs on sample data, with the neutral theme of shadcn/ui.

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​

The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.

pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/how-this-works.json

Usage​

Record a step wherever your app makes a request, and give the list to the panel.

components/explain.tsx
'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 showsCall
The stepsYour own app: record each request where you make it
A token of a stepThe answer of the token endpoint. The token inspector decodes it.
The docs link of a stepA page of docs.lumoauth.dev

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • 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​

PropTypeDefaultDescription
stepsrequiredFlowStep[]The steps of the flow, in order.
titlestring'How this works'The title of the panel.
defaultOpenbooleantrueOpen the panel at first.
classNamestringClass name for the panel.

FlowStep​

OptionTypeDescription
idrequiredstringAn ID for the step.
titlerequiredstringWhat happens, in plain words.
staterequired'pending' | 'active' | 'done' | 'failed'The state of the step.
request{ method: string; url: string }The request of the step.
statusnumberThe HTTP status of the answer.
notestringOne or two sentences on what LumoAuth did.
errorstringThe refusal, for a step that failed.
tokenstringA token that the step returned. It is shown decoded.
docsHrefstringThe docs page of this step.