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

Closed
opened 2026-04-13 09:59:06 -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: Merged
Merged: 3/30/2026
Merged by: @gustavovalverde

Base: mainHead: feat/passkey-preauth-extensions


📝 Commits (1)

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

📊 Changes

10 files changed (+921 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 (+150 -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, server/client WebAuthn extensions, and verification hooks. Enables passkey-first onboarding and PRF-based identity derivation without changing defaults. Addresses #7151.

  • New Features

    • Pre-auth registration: set registration.requireSession=false; when no session, require registration.resolveUser({ ctx, context }); client can pass context to options and registration; forwarded into resolveUser and registration.afterVerification.
    • User linking: registration.afterVerification may return { userId }; validated and must match session user if present; new error codes: SESSION_REQUIRED, RESOLVE_USER_REQUIRED, RESOLVED_USER_INVALID.
    • Extensions: server-defined extensions for registration/auth (object or (ctx) => inputs); client can pass extensions; SDK merges client+server.
    • WebAuthn response: set returnWebAuthnResponse to get raw response and clientExtensionResults for registration and authentication; client omits clientExtensionResults when posting to server.
    • Hooks: added authentication.afterVerification.
    • Docs and tests updated, including client merge tests and e2e pre-auth smoke.
  • Migration

    • No changes unless you opt in.
    • To use pre-auth: set requireSession=false, implement resolveUser, and pass context from the client on options and registration.
    • To use extensions/results: configure plugin registration.extensions/authentication.extensions or pass client extensions, and set returnWebAuthnResponse on the client.

Written for commit ad30601389. 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:** ✅ Merged **Merged:** 3/30/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `feat/passkey-preauth-extensions` --- ### 📝 Commits (1) - [`ad30601`](https://github.com/better-auth/better-auth/commit/ad3060138961af9b9b8f73a39bc995daa66cd8b2) feat(passkey): add pre-auth registration and extensions ### 📊 Changes **10 files changed** (+921 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` (+150 -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, server/client WebAuthn extensions, and verification hooks. Enables passkey-first onboarding and PRF-based identity derivation without changing defaults. Addresses #7151. - **New Features** - Pre-auth registration: set `registration.requireSession=false`; when no session, require `registration.resolveUser({ ctx, context })`; client can pass `context` to options and registration; forwarded into `resolveUser` and `registration.afterVerification`. - User linking: `registration.afterVerification` may return `{ userId }`; validated and must match session user if present; new error codes: `SESSION_REQUIRED`, `RESOLVE_USER_REQUIRED`, `RESOLVED_USER_INVALID`. - Extensions: server-defined `extensions` for registration/auth (object or `(ctx) => inputs`); client can pass `extensions`; SDK merges client+server. - WebAuthn response: set `returnWebAuthnResponse` to get raw response and `clientExtensionResults` for registration and authentication; client omits `clientExtensionResults` when posting to server. - Hooks: added `authentication.afterVerification`. - Docs and tests updated, including client merge tests and e2e pre-auth smoke. - **Migration** - No changes unless you opt in. - To use pre-auth: set `requireSession=false`, implement `resolveUser`, and pass `context` from the client on options and registration. - To use extensions/results: configure plugin `registration.extensions`/`authentication.extensions` or pass client `extensions`, and set `returnWebAuthnResponse` on the client. <sup>Written for commit ad3060138961af9b9b8f73a39bc995daa66cd8b2. 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-04-13 09:59:06 -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#15352