Skip to main content

Approval request

A card that shows what an agent wants to do, why, and for how long, with Approve and Deny.

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

The single request that a person decides on. The agent has stopped, and it continues only after a person answers. Press a button: the preview waits a moment, as a real request would, then shows the decision.

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/approval-request.json

Usage​

The card takes one request and two callbacks. fromJitRequest maps a row of the pending list, or the payload of the jit.approval_required webhook, to the request.

app/approvals/[id]/approval.tsx
'use client';

import { ApprovalRequest, fromJitRequest } from '@/components/approval-request';

export function Approval({ row }: { row: Record<string, unknown> }) {
const decide = (decision: 'approve' | 'deny') => async (id: string, note: string) => {
await fetch(`/api/approvals/${id}/${decision}`, { method: 'POST', body: JSON.stringify({ note }) });
};

return <ApprovalRequest request={fromJitRequest(row)} onApprove={decide('approve')} onDeny={decide('deny')} />;
}

Your API route makes the call to LumoAuth with the access token of the approver. Never call LumoAuth from the browser with a secret.

Where the data comes from​

What the card showsCall
The pending requestsGET /jit/pending, or lumo.jit.listPendingRequests()
A request as it arrivesThe webhook jit.approval_required
Approve or denyPOST /jit/approve/{id}, POST /jit/deny/{id}
The state of one requestGET /jit/request/{id}/status, or lumo.jit.getRequestStatus()

The card shows the fields of the request as LumoAuth sends them: justification, risk_level, authorization_details (one object), requested_ttl, expires_at and on_behalf_of. The webhook also sends a summary, such as "Invoice Copilot wants to refund on payment_initiation INV-4471". The pending list has none, so fromJitRequest builds the same words from authorization_details.

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • Approved and denied, with who decided and when.
  • Approved by a rule. Pass the name of the rule as decidedBy.
  • Expired. A pending request whose time ran out shows this state by itself.
  • Not yours to decide. disabledReason disables the buttons and says why.

Props​

PropTypeDescription
requestrequiredApprovalRequestDataThe request. Its state is pending unless you set state.
onApprove(id: string, note: string) => void | Promise<void>Called when the person approves. Return a promise, and the button shows progress until it settles.
onDeny(id: string, note: string) => void | Promise<void>Called when the person denies.
disabledReasonstringWhy this person cannot decide. The buttons are disabled and the note field gives way to this text.
classNamestringClass name for the card.

ApprovalRequestData​

OptionTypeDefaultDescription
idrequiredstringThe request ID (request_id).
agentNamerequiredstringThe name of the agent.
summaryrequiredstringThe action in plain words.
onBehalfOfstring | nullThe person that the agent acts for.
justificationstring | nullThe reason that the agent gave.
impact'low' | 'medium' | 'high' | 'critical'The risk level of the request.
detailsRecord<string, unknown>[]The structured detail: authorization_details.
ttlSecondsnumber | nullHow long the permission lasts after approval.
expiresAtstring | nullWhen the request stops waiting. The card counts down to it.
state'pending' | 'approved' | 'denied' | 'expired''pending'The state of the request.
decidedBystring | nullWho decided, or the rule that approved the request.
decidedAtstring | nullWhen the decision was made.