Connected accounts
The list of outside services that an agent can use for a person, with connect and disconnect for each.
The place where a person decides which of their accounts an agent may use. The agent never sees the credentials: it asks LumoAuth for a token when it needs one.
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/connections.json
npx shadcn@latest add https://examples.lumoauth.dev/r/connections.json
yarn dlx shadcn@latest add https://examples.lumoauth.dev/r/connections.json
bunx --bun shadcn@latest add https://examples.lumoauth.dev/r/connections.json
Add the shadcn/ui components that the pattern uses.
npx shadcn@latest add badge buttonInstall the packages.
npm install lucide-reactCopy the code into your project.
components/connections.tsx'use client';import * as React from 'react';import { Bot, Link2, Plug, RefreshCw, Unplug } from 'lucide-react';import { Badge } from '@/components/ui/badge';import { Button } from '@/components/ui/button';import { cn } from '@/lib/utils';export interface ConnectionData {id: string;name: string;/** The key of the service: `github`, `google`, `slack`… */provider: string;/** The name of the service to show. */providerLabel?: string;scopes?: string[];/** True when the person linked their account for this connection. */linked?: boolean;/** The linked account, for example a user name at the service. */account?: string | null;/** True when the service asks the person to give consent again. */needsConsent?: boolean;/** The agents that may use this connection. */agents?: string[];}/** Maps a row of `GET /agents/me/connections` to a connection. */export function fromAgentConnection(row: Record<string, any>): ConnectionData {return {id: String(row.connection_id),name: row.name ?? row.provider_label ?? row.provider,provider: row.provider,providerLabel: row.provider_label,scopes: Array.isArray(row.scopes) ? row.scopes : [],};}export interface ConnectionsProps {connections: ConnectionData[];/** Start the consent of the service for this connection. */onLink?: (id: string) => void | Promise<void>;onUnlink?: (id: string) => void | Promise<void>;className?: string;}export function Connections({ connections, onLink, onUnlink, className }: ConnectionsProps) {const [busy, setBusy] = React.useState<string | null>(null);const run = (id: string, action?: (id: string) => void | Promise<void>) => async () => {setBusy(id);try {await action?.(id);} finally {setBusy(null);}};if (connections.length === 0) {return (<div className={cn('grid w-full max-w-lg justify-items-center gap-1 rounded-lg border border-dashed p-8 text-center text-sm', className)}><Plug className="size-6 text-muted-foreground" aria-hidden="true" /><p className="font-medium">No accounts to connect</p><p className="text-muted-foreground">Your organization has not set up a service that agents can use for you.</p></div>);}return (<ul className={cn('grid w-full max-w-lg gap-3 text-sm', className)} aria-label="Connected accounts">{connections.map((c) => {const label = c.providerLabel ?? c.provider;return (<li key={c.id} className="rounded-lg border bg-card text-card-foreground"><div className="flex items-start gap-3 p-3"><span className="flex size-9 shrink-0 items-center justify-center rounded-md bg-muted text-xs font-semibold uppercase">{label.slice(0, 2)}</span><div className="grid min-w-0 flex-1 gap-0.5"><p className="flex flex-wrap items-center gap-2 font-medium"><span className="truncate">{c.name}</span>{c.linked && !c.needsConsent && (<Badge className="border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-400">Connected</Badge>)}{c.needsConsent && (<Badge className="border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-400">Needs your consent again</Badge>)}</p><p className="truncate text-muted-foreground">{c.linked && c.account ? `${label} · ${c.account}` : `${label} · not connected`}</p></div>{c.needsConsent ? (<Button size="sm" disabled={busy === c.id} onClick={run(c.id, onLink)}><RefreshCw aria-hidden="true" />Reconnect</Button>) : c.linked ? (<Button size="sm" variant="outline" disabled={busy === c.id} onClick={run(c.id, onUnlink)}><Unplug aria-hidden="true" />Disconnect</Button>) : (<Button size="sm" disabled={busy === c.id} onClick={run(c.id, onLink)}><Link2 aria-hidden="true" />Connect</Button>)}</div>{((c.scopes && c.scopes.length > 0) || (c.agents && c.agents.length > 0)) && (<div className="grid gap-2 border-t px-3 py-2">{c.scopes && c.scopes.length > 0 && (<div className="flex flex-wrap items-center gap-1"><span className="mr-1 text-xs text-muted-foreground">Agents will be able to use</span>{c.scopes.map((scope) => (<Badge key={scope} variant="secondary" className="font-mono font-normal">{scope}</Badge>))}</div>)}{c.agents && c.agents.length > 0 && (<p className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground"><Bot className="size-3.5" aria-hidden="true" />{c.agents.join(', ')}</p>)}</div>)}</li>);})}</ul>);}Change the import paths if your project keeps its components in another place.
Usage
fromAgentConnection maps a row of the connections list. Whether the person linked the account is a fact of your own app, so set linked yourself.
'use client';
import { Connections, fromAgentConnection } from '@/components/connections';
export function ConnectedAccounts({ rows, linkedIds, accountUrl }: {
rows: Array<Record<string, unknown>>;
linkedIds: string[];
accountUrl: string; // the connections page of your LumoAuth organization
}) {
const connections = rows.map(fromAgentConnection).map((c) => ({ ...c, linked: linkedIds.includes(c.id) }));
// A person links and unlinks an account on the hosted account pages.
const open = () => window.location.assign(accountUrl);
return <Connections connections={connections} onLink={open} onUnlink={open} />;
}
LumoAuth runs the consent of each outside service on its hosted page "Accounts agents can use" (/account/connections). Send the person there for both actions. The account pages entry shows that page.
Where the data comes from
| What the pattern shows | Call |
|---|---|
| The connections that an agent can use | GET /agents/me/connections: connection_id, name, provider, provider_label, scopes |
| A token for one connection and one person | POST /agents/me/connections/{connection_id}/token with user_id |
| Link and unlink an account | The hosted page /account/connections |
States
- The service asks for consent again.
- Nothing to connect. The organization set up no service.
Props
| Prop | Type | Description |
|---|---|---|
connectionsrequired | ConnectionData[] | The connections to show. |
onLink | (id: string) => void | Promise<void> | Called for Connect and for Reconnect. |
onUnlink | (id: string) => void | Promise<void> | Called for Disconnect. |
className | string | Class name for the list. |
ConnectionData
| Option | Type | Description |
|---|---|---|
idrequired | string | The connection ID. |
namerequired | string | The name of the connection. |
providerrequired | string | The key of the service, for example github. |
providerLabel | string | The name of the service to show. |
scopes | string[] | What agents will be able to use. |
linked | boolean | True when the person linked their account. |
account | string | null | The linked account. |
needsConsent | boolean | True when the service asks the person to give consent again. |
agents | string[] | The agents that may use this connection. |