Skip to content

feat: offer a passkey after signing in - #4438

Merged
richiemcilroy merged 21 commits into
mainfrom
feat/passkey-prompt
Nov 21, 2026
Merged

richiemcilroy merged 21 commits into
mainfrom
feat/passkey-prompt

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What

After someone signs in without a passkey, the dashboard now asks once whether they want to add one.

  • Add passkey: if they signed in within the last 10 minutes, this goes straight to Face ID, Touch ID, Windows Hello or their password manager, with no extra email code. They just proved they own the account.
  • Not now: hides the offer for 30 days. This is stored on the account (users.preferences.passkeyPromptDismissedAt), so it doesn't follow them to every device.
  • The offer only appears when the sign-in is fresh, the account has no passkeys, and the device has a built-in authenticator (platformAuthenticatorIsAvailable).
  • Adding a passkey from Settings is unchanged and still asks the person to confirm it's them.

How

  • Sign-in time. The NextAuth jwt callback stamps authTime when someone signs in (the callback runs with user). Later refreshes keep it, and tokens from before this change have none. The time lives inside the encrypted session token, so a client can't set it. session exposes it to the server.
  • Freshness check. isFreshSignIn (in packages/database/auth/fresh-sign-in.ts) means the sign-in was within the last 10 minutes and is no more than 60 s in the future.
  • New server action. getPasskeyRegistrationOptionsAfterSignIn issues registration options only when the session belongs to the signed-in account, its sign-in is fresh, and the account has no passkeys. Otherwise it returns verify. Completing registration goes through the existing completePasskeyRegistration, which keeps all of feat: sign in with passkeys #4435's checks: user verification, the session-version check under the user row lock, the 10-passkey cap, and the "passkey added" email.
  • Dashboard check. shouldOfferPasskey runs in the dashboard layout, in parallel with the existing loads. It reads the session, skips snoozed accounts, and counts passkeys. Any error means "don't show the offer", so it can't break the dashboard.

Security

The only new capability is: within 10 minutes of a real sign-in, an account with no passkeys can add its first one without a separate code. Being signed in for under 10 minutes counts as proof it's the account owner. A passkey added this way is sign-in only: it can never confirm identity.

  • Sign-in only, enforced in two places.
    • New column user_passkeys.confirmsIdentity (migration 0065, additive, defaults to true so existing passkeys are unchanged).
    • No-code passkeys are stored with false.
    • They are left out of "confirm it's you" options, and an assertion from one is refused for step-up even if a challenge is smuggled in.
    • So a no-code passkey can't mint a step-up grant, which means it can't add or remove passkeys or start an email change. A briefly stolen session therefore can't escalate into a takeover; an earlier review found that path and this closes it.
  • Removing a passkey now needs confirmation (a step-up grant), so a session alone can't clear passkeys to reopen the no-code route.
  • A passkey sign-in never opens the no-code route. The session token records how the person signed in (authMethod, stamped with authTime and never changed by refresh or update()). The no-code route and the prompt refuse passkey sign-ins and sessions with no recorded method. Otherwise someone holding a sign-in-only passkey could keep signing in with it, wait for the owner to remove it, and add another.
  • The window can't be forged or extended.
    • authTime is written only by the jwt callback when NextAuth completes a sign-in; refreshes and client update() calls leave it untouched (tested).
    • It lives in the encrypted token, and nothing else mints session cookies.
    • Freshness is checked when options are issued and again when the passkey is saved.
  • First passkey only. The no-code options use their own purpose (passkey_first_registration). The insert re-checks that the account has no passkeys, under the user row lock, and any added passkey spends every outstanding setup.
  • Same protections as Settings: user verification, the session-version check under the lock, the 10-passkey cap, rate limits, and the "passkey added" email.
  • "Sign out of all devices" is now one shared revokeAllCredentials, used by settings, the agent API and the mobile account deletion request, so the three can't drift apart. On top of sessions, keys and passkeys, it now also disconnects MCP apps and voids pending CLI login codes. The mobile path now also clears pending email changes.
    • Existing MCP tokens are revoked, and unused authorization codes are voided, so a code issued just before sign-out can't be exchanged afterwards.
    • Issuing an MCP or CLI code, exchanging it and refreshing an MCP token all take the account row lock first, the same row sign-out bumps. Issuing also re-checks the session version under that lock, so a request racing sign-out can't mint a code.
    • New indexes mcp_oauth_tokens (userId, revokedAt) and mcp_oauth_codes (userId, consumedAt) keep both updates off a full table scan (EXPLAIN shows a range scan on each).
  • Remaining risk: someone who steals a session cookie within 10 minutes of a sign-in, on an account with no passkeys, could add one sign-in-only passkey. That lets them sign in later, as a stolen session already does, but not change the email or credentials. The owner is emailed and can remove it after confirming it's them, or use "Sign out of all devices".

Testing

  • Unit (auth-options.test.ts):
    • The sign-in time is stamped on sign-in, kept on refresh, and absent on legacy tokens.
    • The session exposes it.
  • Database (passkeys-database.test.ts):
    • Registration from the prompt is refused for a sign-in older than 10 minutes, a missing sign-in time, a future sign-in time, or another account's session.
    • A fresh sign-in registers a passkey without a code.
    • The offer shows only with a fresh sign-in and no passkeys, Not now snoozes it for 30 days, and other preferences are kept.
    • A passkey sign-in can't reopen the no-code route after its passkey is removed: no prompt, options refused, and a leftover challenge is refused at completion. A session with no recorded sign-in method is refused too.
    • Sign-out voids pending CLI login codes.
    • MCP: a pending code can't be exchanged after sign-out, a code can't be issued from a signed-out session, a pre-sign-out refresh token is refused, and six rounds of exchange + refresh racing sign-out never leave a live token.
  • Real requests against next dev, 13/13:
    • POST /api/v1/me/sign-out-all voids pending MCP and CLI codes and revokes the MCP token. A late CLI code exchange gets 401, and a CLI key issued before sign-out gets 401.
    • The mobile account deletion request revokes the MCP token, voids both kinds of code and removes the mobile key.
  • Mutation check: I removed each guard in turn (freshness, same account, the 10-minute window, the future-time limit, the snooze, the passkey count, stamping only at sign-in, the first-passkey-only precheck, and the action requesting it), and a test fails each time. The in-lock first-passkey check and the setup spend back each other up; removing both fails the race test. Dropping the MCP or CLI code voiding, the session-version check, the passkey sign-in check or the missing-method check each fails a test. The account lock on exchange and refresh is a backstop: InnoDB row locks already serialize those writes, so removing it alone doesn't fail a test.
  • Real browser (Chrome with its built-in WebAuthn virtual authenticator, next dev, real MySQL), 12/12:
    • A fresh email sign-in shows the offer, Add passkey creates one with no security code, the offer doesn't come back, and the new passkey signs in.
    • There's no offer after a passkey sign-in, even after that passkey is removed.
    • A second account's Not now is stored on the account, hides the offer after reload, and adds nothing.
  • The existing passkey browser test still passes 13/13, and the email change browser test 15/15.
  • auth-options.test.ts also covers authMethod: stamped at sign-in, kept on refresh, not changeable through update().
  • tsc --noEmit for apps/web and Biome are clean.

Migration 0065_passkey_confirms_identity adds one boolean column with a default and two secondary indexes on the small MCP tables. It ships through a PlanetScale deploy request before this merges.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was found.

Summary

This PR offers eligible users their first passkey after signing in and strengthens account-wide sign-out.

  • A fresh non-passkey sign-in can offer to add a first passkey.
  • Passkeys added from the offer can sign in but cannot confirm account changes.
  • Signing out everywhere also revokes connected apps and pending login codes.

Reviews (10) · Last reviewed commit: "fix(passkeys): show a passkey added from..." · Reviewed by Greptile

@sandchest-com

sandchest-com Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Sandchest

Sandchest reviewed 1b26808: nothing exploitable found in this change.

Sandchest reviews every change for vulnerabilities an attacker could use · 11 credits · Review details

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 2 other findings in Capy.

Open in Capy

# Conflicts:
#	packages/database/package.json
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Nov 21, 2026 12:35am UTC

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

Open in Capy

@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 20, 2026 22:55 Inactive
@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

Open in Capy

@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 3 other findings in Capy.

Open in Capy

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 21, 2026 00:01 Inactive

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found 1 potential issue (1 medium).

View 1 other finding in Capy.

Open in Capy

Sign-out now marks unused authorization codes as consumed in both the
settings and agent API paths, and code issue, exchange and refresh take
the account row lock first. Issuing a code also checks the session
version under that lock, so a request racing sign-out can't mint one.
@vercel
vercel Bot temporarily deployed to Preview – cap-status November 21, 2026 00:08 Inactive

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 2 other findings in Capy.

Open in Capy

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

Open in Capy

The session token now records how the person signed in. The no-code
first-passkey route and the dashboard prompt refuse passkey sign-ins
and sessions with no recorded method, so removing a sign-in-only
passkey can't be followed by adding another from a passkey session.
Settings, the agent API and the mobile account deletion request now
call revokeAllCredentials, which also voids pending CLI login codes and
clears email change requests on the mobile path. CLI code issue and
exchange take the account row lock, and issuing re-checks the session
version, matching MCP.

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 21, 2026 00:27 Inactive

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai please re-review the latest head (521a712): MCP and CLI codes voided on sign-out, shared revokeAllCredentials, sign-in method recorded so passkey sign-ins can't use the no-code route.

The list kept its first props, so a passkey added through the dashboard
prompt on the Account page stayed hidden until a full reload. Take the
server's list whenever router.refresh() delivers a new one.
@vercel
vercel Bot temporarily deployed to Preview – cap-status November 21, 2026 00:35 Inactive
@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai please re-review the latest head (1b26808).

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@richiemcilroy
richiemcilroy merged commit 5e18a3f into main Nov 21, 2026
49 checks passed

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cap-web — 1b26808b Deployed Nov 21, 2026 by vercel[bot]
Preview – cap-status — 1b26808b Deployed Nov 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant