[PR #6445] feat(passkey): Passkey Sign-In Using Email #6670

Open
opened 2026-03-13 13:07:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6445
Author: @Ridhim-RR
Created: 12/1/2025
Status: 🔄 Open

Base: canaryHead: feat/passkey-signIn-with-email


📝 Commits (4)

  • 112712f feat(passkey): Passkey Sign-In Using Email
  • 9c5732e Update packages/passkey/src/index.ts
  • 5058a4d Update docs/content/docs/plugins/passkey.mdx
  • 202e0f3 Merge branch 'canary' into feat/passkey-signIn-with-email

📊 Changes

4 files changed (+106 additions, -2 deletions)

View changed files

📝 docs/content/docs/plugins/passkey.mdx (+16 -0)
📝 packages/passkey/src/client.ts (+11 -0)
📝 packages/passkey/src/index.ts (+39 -2)
📝 packages/passkey/src/passkey.test.ts (+40 -0)

📄 Description

Closes #6165

Add email parameter support for passkey sign-in

Problem

Currently, the passkey sign-in flow does not accept an email or account identifier. When a device contains multiple passkeys from different accounts, the browser prompts the user to select which passkey to use, breaking the UX for applications that already collect the user's email before initiating the WebAuthn request.

Issue: Without a session, the endpoint cannot determine which user's passkeys to use, resulting in an empty allowCredentials array. This causes the browser to show all passkeys on the device, requiring manual selection.

Solution

Add support for passing an email parameter to the passkey sign-in function. When provided, the server looks up the user by email (even without a session), finds their passkeys, and populates allowCredentials in the WebAuthn options. This enables the browser to skip the account-selection step and directly invoke the correct passkey.

Changes

Server-side (packages/passkey/src/index.ts)

  • Added optional email query parameter to generatePasskeyAuthenticationOptions endpoint
  • Added logic to look up user by email when no session exists but email is provided
  • Populate allowCredentials with the user's passkeys when email lookup succeeds
  • Store user ID in challenge data even when email is provided (for verification flow)

Client-side (packages/passkey/src/client.ts)

  • Added optional email parameter to signInPasskey() function
  • Pass email as query parameter to the authentication options endpoint
  • Added JSDoc documentation explaining the email parameter usage

Tests (packages/passkey/src/passkey.test.ts)

  • Added test case: "should have allowCredentials populated if the session is not provided but email is provided"
  • Verifies that allowCredentials is populated with user's passkeys when email is provided without session

Docs (passkey.mdx)

  • Add an example demonstrating the usage

Usage

// In your sign-in form
await signIn.passkey({
  email: userEmail, // Pass the email here
  fetchOptions: {
    onSuccess() {
      // Handle success
    }
  }
});

When the email is provided:

  • The server looks up the user's passkeys
  • allowCredentials is populated with only that user's passkeys
  • The browser shows only those passkeys (or auto-selects if there's only one)
  • No account selection UI is shown

Summary by cubic

Added optional email hinting to passkey sign-in to preselect the correct account and populate allowCredentials, removing the browser’s account picker. Works without a session by looking up the user by email.

  • New Features
    • Server: /passkey/generate-authenticate-options accepts optional email, looks up user when no session, populates allowCredentials, and stores userId in challenge.
    • Client: signIn.passkey supports an email parameter and forwards it to the server.
    • Tests: added coverage for email flow without a session.
    • Docs: added example showing email-based passkey sign-in.

Written for commit 202e0f310f. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6445 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 12/1/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/passkey-signIn-with-email` --- ### 📝 Commits (4) - [`112712f`](https://github.com/better-auth/better-auth/commit/112712f222784b12326a2aee27df07ec256d4003) feat(passkey): Passkey Sign-In Using Email - [`9c5732e`](https://github.com/better-auth/better-auth/commit/9c5732ea9753eddc9c84f6c972f89a91cd855f3b) Update packages/passkey/src/index.ts - [`5058a4d`](https://github.com/better-auth/better-auth/commit/5058a4d09195d9333bd1350e2ebf324ea42eb3b3) Update docs/content/docs/plugins/passkey.mdx - [`202e0f3`](https://github.com/better-auth/better-auth/commit/202e0f310fa4fbd5188e1a4e503739923a00ed93) Merge branch 'canary' into feat/passkey-signIn-with-email ### 📊 Changes **4 files changed** (+106 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/passkey.mdx` (+16 -0) 📝 `packages/passkey/src/client.ts` (+11 -0) 📝 `packages/passkey/src/index.ts` (+39 -2) 📝 `packages/passkey/src/passkey.test.ts` (+40 -0) </details> ### 📄 Description Closes #6165 # Add email parameter support for passkey sign-in ## Problem Currently, the passkey sign-in flow does not accept an email or account identifier. When a device contains multiple passkeys from different accounts, the browser prompts the user to select which passkey to use, breaking the UX for applications that already collect the user's email before initiating the WebAuthn request. **Issue:** Without a session, the endpoint cannot determine which user's passkeys to use, resulting in an empty `allowCredentials` array. This causes the browser to show all passkeys on the device, requiring manual selection. ## Solution Add support for passing an email parameter to the passkey sign-in function. When provided, the server looks up the user by email (even without a session), finds their passkeys, and populates `allowCredentials` in the WebAuthn options. This enables the browser to skip the account-selection step and directly invoke the correct passkey. ## Changes ### Server-side (`packages/passkey/src/index.ts`) - Added optional `email` query parameter to `generatePasskeyAuthenticationOptions` endpoint - Added logic to look up user by email when no session exists but email is provided - Populate `allowCredentials` with the user's passkeys when email lookup succeeds - Store user ID in challenge data even when email is provided (for verification flow) ### Client-side (`packages/passkey/src/client.ts`) - Added optional `email` parameter to `signInPasskey()` function - Pass email as query parameter to the authentication options endpoint - Added JSDoc documentation explaining the email parameter usage ### Tests (`packages/passkey/src/passkey.test.ts`) - Added test case: "should have allowCredentials populated if the session is not provided but email is provided" - Verifies that `allowCredentials` is populated with user's passkeys when email is provided without session ### Docs (`passkey.mdx`) - Add an example demonstrating the usage ## Usage ```typescript // In your sign-in form await signIn.passkey({ email: userEmail, // Pass the email here fetchOptions: { onSuccess() { // Handle success } } }); ``` When the email is provided: - The server looks up the user's passkeys - `allowCredentials` is populated with only that user's passkeys - The browser shows only those passkeys (or auto-selects if there's only one) - No account selection UI is shown <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added optional email hinting to passkey sign-in to preselect the correct account and populate allowCredentials, removing the browser’s account picker. Works without a session by looking up the user by email. - **New Features** - Server: /passkey/generate-authenticate-options accepts optional email, looks up user when no session, populates allowCredentials, and stores userId in challenge. - Client: signIn.passkey supports an email parameter and forwards it to the server. - Tests: added coverage for email flow without a session. - Docs: added example showing email-based passkey sign-in. <sup>Written for commit 202e0f310fa4fbd5188e1a4e503739923a00ed93. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:07:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6670