import { AgentAvatar, Banner, Button, ClipboardText, Empty, Input, Table } from "@refs/design-system"; import { LayerCard } from "@refs/design-system"; import { KeyIcon, PlugsConnectedIcon } from "@refs/design-system/icons"; import { Form, useNavigation } from "react-router"; import type { Route } from "./+types/tokens"; import { AppShell, PageHeader } from "../components/shell"; import { formatDate } from "@refs/design-system"; import { failed, formText, signedIn } from "../lib/session"; export const meta: Route.MetaFunction = () => [{ title: "Access tokens ยท refs" }]; export async function loader({ context }: Route.LoaderArgs) { const me = await signedIn(context).me(); const [tokens, grants] = await Promise.all([me.tokens(), me.agentGrants()]); return { tokens, grants }; } export async function action({ request, context }: Route.ActionArgs) { const me = await signedIn(context).me(); const form = await request.formData(); switch (formText(form, "intent")) { case "revoke": case "disconnect": { const id = formText(form, "id"); const outcome = formText(form, "intent") === "revoke" ? await me.revokeToken(id) : await me.revokeAgentGrant(id); return outcome.ok ? { created: null, error: null } : failed(outcome.problem, { created: null }); } case "create": { const outcome = await me.createToken(formText(form, "name")); if (!outcome.ok) return failed(outcome.problem, { created: null }); return { created: { name: outcome.value.token.name, token: outcome.value.secret }, error: null }; } default: return failed({ code: "invalid", message: "Unknown token action." }, { created: null }); } } export default function Tokens({ loaderData, actionData }: Route.ComponentProps) { const navigation = useNavigation(); const creating = navigation.state === "submitting" && navigation.formData?.get("intent") === "create"; return (
{actionData?.error && } {actionData?.created && ( You won't be able to see it again. } /> )}
{loaderData.tokens.length === 0 ? ( } title="No access tokens" description="Generate one to clone and push over HTTPS." /> ) : ( Name Created Last used {loaderData.tokens.map((token) => ( {token.name} {formatDate(token.createdAt)} {formatDate(token.lastUsedAt)}
))}
)}
); } function ConnectedAgents({ grants }: { grants: Route.ComponentProps["loaderData"]["grants"] }) { return (

Connected agents

Agent clients you signed in with OAuth, such as Claude Code or Codex. Disconnecting one signs it out and takes your agents offline.

{grants.length === 0 ? ( } title="No agents connected" description="Sign in from Claude Code or Codex to connect one." /> ) : ( Client Connected {grants.map((grant) => ( {grant.client} {formatDate(grant.createdAt)}
))}
)}
); }