[PR #7154] feat(passkey): add pre-auth registration and extensions #7105

Open
opened 2026-03-13 13:24:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7154
Author: @gustavovalverde
Created: 1/6/2026
Status: 🔄 Open

Base: canaryHead: feat/passkey-preauth-extensions


📝 Commits (1)

  • 4136eb7 feat(passkey): add pre-auth registration and extensions

📊 Changes

10 files changed (+920 additions, -28 deletions)

View changed files

📝 docs/content/docs/plugins/passkey.mdx (+89 -0)
📝 e2e/smoke/package.json (+4 -0)
e2e/smoke/test/passkey-preauth.spec.ts (+124 -0)
packages/passkey/src/client.test.ts (+147 -0)
📝 packages/passkey/src/client.ts (+70 -4)
📝 packages/passkey/src/error-codes.ts (+4 -0)
📝 packages/passkey/src/passkey.test.ts (+239 -5)
📝 packages/passkey/src/routes.ts (+149 -15)
📝 packages/passkey/src/types.ts (+87 -1)
📝 pnpm-lock.yaml (+7 -3)

📄 Description

Motivation

We need a middle ground where Better Auth remains generic, while allowing apps to plug in advanced passkey flows (PRF-based identity derivation) without custom forks. This change enables pre-auth passkey registration with extension data and keeps Better Auth’s auth flow intact.

Closes #7151

Summary

  • Adds a pre-auth registration flow for passkeys so servers can derive user identity from client extensions (e.g., PRF) before user creation.
  • Allows passing WebAuthn extensions into registration and authentication option generation.
  • Adds optional hooks to post-process verification and surface the WebAuthn response.

Summary by cubic

Adds opt-in pre-auth passkey registration with context forwarding and WebAuthn extensions. Enables passkey-first onboarding and PRF-based identity derivation without changing defaults. Addresses #7151.

  • New Features

    • Pre-auth registration: set registration.requireSession=false; registration.resolveUser({ ctx, context }) is required when no session; forward a context from the client to options and into verification so it reaches resolveUser and afterVerification; registration.afterVerification allows a safe userId override with validation and session checks; new error codes for session/resolveUser/invalid user.
    • Extensions: server-defined extensions (static or resolver) for both registration and authentication; client can pass extensions and the SDK merges them with server values; returnWebAuthnResponse returns the WebAuthn response and clientExtensionResults; authentication.afterVerification hook added. Docs and tests updated, including e2e smoke.
  • Migration

    • No changes unless you opt in.
    • To use pre-auth: set requireSession=false, implement resolveUser, and pass context from the client when generating options (and when registering if needed). To read extension results: pass extensions and set returnWebAuthnResponse on the client.

Written for commit 4136eb7a65077d74845e55705497dbd9cb60bb88. Summary will update 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/7154 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 1/6/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/passkey-preauth-extensions` --- ### 📝 Commits (1) - [`4136eb7`](https://github.com/better-auth/better-auth/commit/4136eb7a65077d74845e55705497dbd9cb60bb88) feat(passkey): add pre-auth registration and extensions ### 📊 Changes **10 files changed** (+920 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/passkey.mdx` (+89 -0) 📝 `e2e/smoke/package.json` (+4 -0) ➕ `e2e/smoke/test/passkey-preauth.spec.ts` (+124 -0) ➕ `packages/passkey/src/client.test.ts` (+147 -0) 📝 `packages/passkey/src/client.ts` (+70 -4) 📝 `packages/passkey/src/error-codes.ts` (+4 -0) 📝 `packages/passkey/src/passkey.test.ts` (+239 -5) 📝 `packages/passkey/src/routes.ts` (+149 -15) 📝 `packages/passkey/src/types.ts` (+87 -1) 📝 `pnpm-lock.yaml` (+7 -3) </details> ### 📄 Description ## Motivation We need a middle ground where Better Auth remains generic, while allowing apps to plug in advanced passkey flows (PRF-based identity derivation) without custom forks. This change enables pre-auth passkey registration with extension data and keeps Better Auth’s auth flow intact. Closes #7151 ## Summary - Adds a pre-auth registration flow for passkeys so servers can derive user identity from client extensions (e.g., PRF) before user creation. - Allows passing WebAuthn extensions into registration and authentication option generation. - Adds optional hooks to post-process verification and surface the WebAuthn response. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds opt-in pre-auth passkey registration with context forwarding and WebAuthn extensions. Enables passkey-first onboarding and PRF-based identity derivation without changing defaults. Addresses #7151. - **New Features** - Pre-auth registration: set `registration.requireSession=false`; `registration.resolveUser({ ctx, context })` is required when no session; forward a `context` from the client to options and into verification so it reaches `resolveUser` and `afterVerification`; `registration.afterVerification` allows a safe `userId` override with validation and session checks; new error codes for session/resolveUser/invalid user. - Extensions: server-defined extensions (static or resolver) for both registration and authentication; client can pass `extensions` and the SDK merges them with server values; `returnWebAuthnResponse` returns the WebAuthn response and `clientExtensionResults`; `authentication.afterVerification` hook added. Docs and tests updated, including e2e smoke. - **Migration** - No changes unless you opt in. - To use pre-auth: set `requireSession=false`, implement `resolveUser`, and pass `context` from the client when generating options (and when registering if needed). To read extension results: pass `extensions` and set `returnWebAuthnResponse` on the client. <sup>Written for commit 4136eb7a65077d74845e55705497dbd9cb60bb88. Summary will update 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:24:18 -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#7105