diff --git a/apps/web/app/(app)/actions.ts b/apps/web/app/(app)/actions.ts index 109446db..bf94cd7b 100644 --- a/apps/web/app/(app)/actions.ts +++ b/apps/web/app/(app)/actions.ts @@ -792,7 +792,7 @@ export async function finishOwnClaudeLoginAction(f: FormData) { const user = asWebActor(await requireUser()); await attempt(f, async () => { const p = await projectForUser(db, user.id, Number(str(f, "projectId"))); - await finishOwnClaudeLogin(db, user, p, Number(str(f, "subscriptionId")), str(f, "code")); + await finishOwnClaudeLogin(db, user, p, Number(str(f, "subscriptionId")), str(f, "code"), str(f, "account")); }); } diff --git a/apps/web/app/(app)/subscriptions/actions.ts b/apps/web/app/(app)/subscriptions/actions.ts index 69106286..87ef4f74 100644 --- a/apps/web/app/(app)/subscriptions/actions.ts +++ b/apps/web/app/(app)/subscriptions/actions.ts @@ -1,7 +1,7 @@ "use server"; // «Подписки» (PEP-67): every action is superadmin-only (others get "not found"). -import { createPool, deletePool, getProject, lendSubscription, PeppaError, returnLoanNow, requireSuperadmin, setProjectPool, updatePool, updateSubscription, type SubscriptionProvider } from "@peppa/core"; +import { createPool, deletePool, getProject, lendSubscription, PeppaError, returnLoanNow, requireSuperadmin, setProjectPool, updatePool, updateSubscription, type SubscriptionProvider, setSubscriptionAccount } from "@peppa/core"; import { addPoolSubscription, addSubscription, cancelLogin, checkSubscription, finishClaudeLogin, removeSubscription, startClaudeLogin, startCodexLogin } from "@peppa/runner"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; @@ -72,7 +72,7 @@ export async function reconnectSubscription(f: FormData) { export async function submitLoginCode(f: FormData) { await attempt(f, async () => { const id = Number(str(f, "id")); - await finishClaudeLogin(db, id, str(f, "code")); + await finishClaudeLogin(db, id, str(f, "code"), str(f, "account")); return `${BASE}?added=${id}#s-${id}`; }); } @@ -95,6 +95,8 @@ export async function renameSubscription(f: FormData) { await attempt(f, async () => { if (!str(f, "name")) throw new PeppaError(m("Нужно название подписки")); await updateSubscription(db, Number(str(f, "id")), { name: str(f, "name") }); + // PEP-178: which account it is — the e-mail the person signed in with. + if (f.has("account")) await setSubscriptionAccount(db, Number(str(f, "id")), str(f, "account")); }); } diff --git a/apps/web/app/(app)/subscriptions/page.tsx b/apps/web/app/(app)/subscriptions/page.tsx index 14978795..c1ec4295 100644 --- a/apps/web/app/(app)/subscriptions/page.tsx +++ b/apps/web/app/(app)/subscriptions/page.tsx @@ -1,7 +1,7 @@ import { notFound } from "next/navigation"; import { ExternalLink, KeyRound, Plus, RefreshCw } from "lucide-react"; import { isSuperadmin, listSubscriptions, OPENCODE_KEY_ENV, PROVIDER_NAMES, poolOverviews, type PoolOverview, type SubscriptionView } from "@peppa/core"; -import { pendingLogin, pollCodexLogin, type PendingLogin } from "@peppa/runner"; +import { pendingLogin, pollCodexLogin, type PendingLogin, backfillCodexAccounts } from "@peppa/runner"; import { AutoRefresh } from "@/components/AutoRefresh"; import { PoolSubscriptions, PoolSummary, PoolSwitches } from "@/components/PoolSubscriptions"; import { Hidden } from "@/components/cards"; @@ -26,6 +26,7 @@ import { returnLoanAction, reconnectSubscription, submitLoginCode, + renameSubscription, updatePoolAction, } from "./actions"; @@ -53,6 +54,7 @@ function LoginSteps({ s, login, t }: { s: SubscriptionView; login: PendingLogin;
> @@ -137,6 +139,22 @@ function SetCard({ o, subs, t }: { o: PoolOverview; subs: SubscriptionView[]; t: o={o} action={(s) => ( <> + {/* PEP-178: name and account of the subscription — which login it is. */} +