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

@ -0,0 +1,38 @@
/* Settings: add a passkey to the signed-in account (a second proof for vault recovery).
Uses the @simplewebauthn/browser UMD bundle (/vendor) and the same endpoints as sign-up. */
(function () {
var btn = document.getElementById("passkey-add");
var msg = document.getElementById("passkey-add-msg");
if (!btn) return;
function csrf() {
var m = document.cookie.match(/(?:^|; )mc_csrf=([^;]+)/);
return m ? decodeURIComponent(m[1]) : "";
}
function post(url, body) {
return fetch(url, {
method: "POST",
headers: { "content-type": "application/json", "x-csrf-token": csrf() },
body: JSON.stringify(body || {}),
});
}
function say(t) { if (msg) msg.textContent = t; }
btn.addEventListener("click", async function () {
btn.disabled = true;
say("Waiting for your device…");
try {
var optsRes = await post("/auth/passkey/register/options");
var opts = await optsRes.json();
if (!optsRes.ok) throw new Error(opts.error || "Could not start.");
var att = await SimpleWebAuthnBrowser.startRegistration({ optionsJSON: opts });
var r = await post("/auth/passkey/register/verify", att);
var out = await r.json();
if (!r.ok || !out.ok) throw new Error(out.error || "Could not add the passkey.");
location.href = "/settings?passkey=added#vault-recovery";
} catch (e) {
say(e && e.message ? e.message : "Could not add a passkey.");
btn.disabled = false;
}
});
})();