feat(settings): add a passkey or connect CoinPay to an existing account (#306)

Assisted recovery (#305) confirms with a passkey or a connected CoinPay
identity, but an account that signed up by email had no way to get either:
the passkey button exists only on the sign-in page, and Sign in with CoinPay
only ever created a new account.

- Settings > Vault email recovery shows what the account has and an "Add a
  passkey" button (the existing register endpoints, which already attach to
  the signed-in user).
- "Connect CoinPay" (shown when CoinPay sign-in is configured) binds the
  CoinPay subject to the signed-in account. An identity that already belongs
  to another account is refused; an account keeps its first identity.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-12-02 22:27:29 -08:00 • committed by GitHub
parent 6ff3089088
commit e04531b73a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 99 additions and 2 deletions

View file

@ -488,3 +488,24 @@ test("assisted: the confirmation page shows for a live link, is gone for a dead
await vr.approveStepup(stepup.id, user.id, "coinpay");
assert.match(await (await realFetch(`${base}/recover/confirm/${stepup.id}`)).text(), /Go back to your terminal/);
});
test("the Settings card offers a way to add the second proof, and shows what the account has", async () => {
const { vaultRecoveryCard } = await import("../src/routes/vault-recovery.mjs");
const card = await vaultRecoveryCard({ user: { id: "u_a", email: "u_a@example.com" }, query: {}, csrfToken: "t" });
assert.match(card, /id="passkey-add"/);
assert.match(card, /no passkey/);
assert.match(card, /\/passkey-add\.js/);
const added = await vaultRecoveryCard({ user: { id: "u_a", email: "u_a@example.com" }, query: { passkey: "added" }, csrfToken: "t" });
assert.match(added, /Passkey added\./);
// An error handed back by the CoinPay round trip is shown escaped.
const bad = await vaultRecoveryCard({ user: { id: "u_a", email: "u_a@example.com" }, query: { coinpay_err: "<b>x</b>" }, csrfToken: "t" });
assert.doesNotMatch(bad, /<b>x<\/b>/);
});
test("linkCoinpay connects an identity only to an account that has none", async () => {
const { linkCoinpay, userByCoinpay } = await import("../src/lib/users.mjs");
await linkCoinpay("u_b", "sub_link_1");
assert.equal((await userByCoinpay("sub_link_1")).id, "u_b");
await linkCoinpay("u_b", "sub_link_2");
assert.ok(!(await userByCoinpay("sub_link_2")), "a second identity does not replace the first");
});