Skip to content
SprecherEast
Issue 1314

feat: Add a passkey from the account page

Back to our plan
Done
enhancementdependenciesfrontendauthpriority: low

Problem

A signed-in resident has no way to add a passkey, so they keep typing a password on their phone.

Proposed fix

  • Package: add @simplewebauthn/server and @simplewebauthn/browser (the security guideline's checks before adding a package, and npm run audit:prod). The server one is used only in the adapter data/webauthn.ts.
  • Use cases in use-cases/addPasskey.ts: ask for registration options (after the session is shown to be a recent sign-in, a few minutes old at most; an older one is sent to sign in again first), then verify the browser's answer against the challenge taken once, and save the passkey with a label.
  • Server actions in actions.ts: parse input again, take the account from the session, return fixed failure codes only.
  • Screen: a "Passkeys" card on /account with an "Add a passkey" button (UI kit Card, Button, Field, Alert, Text; lucide-react icon). The browser's own prompt does the rest. Shown only when the switch is on and the browser supports passkeys.
  • Messages in the one message catalog (platform/lib/messages/accounts.ts), brand voice. Drafts to check against the voice guide:
    • Card lead: "Sign in with your phone's or computer's screen lock instead of a password."
    • Button: "Add a passkey"
    • Success: "Passkey added. Next time, choose Sign in with a passkey."
    • Cancelled: "No passkey was added. You can try again any time."
    • Failure: "We couldn't add that passkey. Please try again."
  • Email: a short note to the account's address that a passkey was added, with what to do if it wasn't them (forgot password, then remove it).
  • Limits on asking for options, reusing guardPublicRequest.

Existing work compared

  • Searched: issues for passkey, account page and WebAuthn; /account today (profile and change password); ui/ChangePasswordForm.client.tsx and cms/requireCurrentPassword.ts (#233).
  • Native: browsers provide the prompt (WebAuthn); Payload and Next.js add nothing for it.
  • Official and community plugins: none fit (#313's table).
  • Our code: chosen on #313. Reuses the session's own sign-in time, the UI kit, the message catalog, the email sender and the limits. No add-a-passkey flow exists, so this is new.

Acceptance criteria

Tests first.

  • Not done: Use-case tests: a session that is too old, no session, a replayed or expired challenge, a different origin or relying party ID, the cap, and the switch off are all refused with fixed codes; a good answer saves one passkey for the session's account only.
  • Not done: Adapter tests: what is asked of the library (residentKey and userVerification set to required explicitly, no attestation, the relying party from the site address, the stored per-account user handle); anything but verified === true, and every thrown error, gives the one fixed failure; a crossOrigin: true answer is refused.
  • Not done: A credential ID already registered on any account is refused and nothing is overwritten; the challenge's account must equal the session's account and the session still be recent when the answer is verified.
  • Not done: Action tests: input parsed again; the account comes only from the session.
  • Not done: Component tests with axe: the card, the button, each message announced.
  • Not done: A resident adds a passkey on a phone and on a desktop browser (checked by hand, and with a virtual authenticator in the e2e run).
  • Not done: /account at 320, 430, 768, 1024, 1280 and 1920 px, light and dark: no overflow, the card lines up with the others, the button is full width on a phone.
  • Not done: The two packages are pinned to exact versions, npm audit signatures passes on them, and a later bump of either gets the top-level review, not a routine merge (record 0021).
  • Not done: /account sends frame-ancestors 'none'; first task: check how the app sends headers today and use that route (record 0021).
  • Not done: The notification email names the passkey's label and the time, and carries no sign-in link.
  • Not done: The accounts note, the knowledge index line and the routes reference change in the same PR.

Files likely touched

  • package.json, package-lock.json
  • src/modules/accounts/data/webauthn.ts (+ test)
  • src/modules/accounts/use-cases/addPasskey.ts (+ test)
  • src/modules/accounts/actions.ts (+ actions.addPasskey.test.ts), server.ts
  • src/modules/accounts/ui/AddPasskey.client.tsx (+ test), ui/passkeyMessages.ts
  • src/platform/lib/messages/accounts.ts
  • src/app/(frontend)/account/page.tsx (+ test)
  • src/modules/accounts/README.md, docs/knowledge/index.md, docs/reference/routes.md

Must not touch

  • src/app/(frontend)/login/** (#1315)
  • src/modules/accounts/data/socialAccounts.ts, data/oauthProviders.ts
  • src/platform/ui/** unless a missing variant is needed, then it becomes its own change with the shared-component label

Open questions

  • None. The step-up is a recent sign-in, decided by the owner on #313 (2026-11-19). The userName and handle storage are on #1313; this step passes the handle from there, never making a second one.

Area

auth, frontend, dependencies

Priority

low


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab