import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { listTokens, createToken, revokeToken, TokenDto } from "../../lib/api"; export const dynamic = "force-dynamic"; export default async function TokensPage({ searchParams }: { searchParams: Promise<{ created?: string }>; }) { const params = await searchParams; const tokens = await listTokens().catch(() => [] as TokenDto[]); async function createTokenAction(formData: FormData) { "use server"; const name = formData.get("name") as string; const scope = formData.get("scope") as string; if (name) { const result = await createToken(name, scope); revalidatePath("/tokens"); redirect(`/tokens?created=${encodeURIComponent(result.token)}`); } } async function revokeTokenAction(formData: FormData) { "use server"; const id = formData.get("id") as string; await revokeToken(id); revalidatePath("/tokens"); } return ( <>

API Tokens

{params.created ? (
Token created (copy it now, it won't be shown again):
{params.created}
) : null}
{tokens.map((token) => ( ))}
Name Scope Prefix Revoked Actions
{token.name} {token.scope} {token.prefix} {token.revoked_at ? "yes" : "no"} {!token.revoked_at && (
)}
); }