[PR #2344] [MERGED] fix: add userDisplayName to the generateRegistrationOptions call #4272

Closed
opened 2026-03-13 11:40:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2344
Author: @EugeneDraitsev
Created: 4/17/2025
Status: Merged
Merged: 4/18/2025
Merged by: @Bekacru

Base: mainHead: main


📝 Commits (1)

  • 1cf9c7b fix: add userDisplayName to the simplewebauthn generateRegistrationOptions call

📊 Changes

1 file changed (+1 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/plugins/passkey/index.ts (+1 -0)

📄 Description

Hi!

This change fixes the YubiKey USB passkey registration flow on mobile devices.

For some reason, registration fails when the displayName field is empty. To reproduce the issue, I’ve prepared a demo project with a basic anonymous + passkey setup:

Here’s a screen recording showing the issue:

https://github.com/user-attachments/assets/4e2d2798-6a8f-41ee-ab09-737e656fe35a

To work around the problem, I added the following logic to auth.ts:

  hooks: {
    after: createAuthMiddleware(async (ctx) => {
      if (ctx.path === '/passkey/generate-register-options') {
        const result = ctx.context.returned as {
          user: { id: string; displayName: string; name?: string };
        };

        const modified = {
          ...result,
          user: {
            ...result?.user,
            displayName: result?.user?.displayName || result?.user?.name
          }
        };

        return ctx.json(modified);
      }
    })
  },

Here’s a live version with the fix applied:
yubikey-better-auth-git-display-name-fix-drais-projects.vercel.app

And a screen recording of it working as expected:

https://github.com/user-attachments/assets/cde03c05-739e-472d-b26d-b2c307d78712

It would be great to get this fix into better-auth, so that YubiKey USB registration works out of the box without needing custom middleware.


🔄 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/2344 **Author:** [@EugeneDraitsev](https://github.com/EugeneDraitsev) **Created:** 4/17/2025 **Status:** ✅ Merged **Merged:** 4/18/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`1cf9c7b`](https://github.com/better-auth/better-auth/commit/1cf9c7bde5ca58f9f5d86bcced1ab429282cfb0c) fix: add userDisplayName to the simplewebauthn generateRegistrationOptions call ### 📊 Changes **1 file changed** (+1 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/passkey/index.ts` (+1 -0) </details> ### 📄 Description Hi! This change fixes the YubiKey USB passkey registration flow on mobile devices. For some reason, registration fails when the `displayName` field is empty. To reproduce the issue, I’ve prepared a demo project with a basic anonymous + passkey setup: - GitHub repo: [yubikey-better-auth](https://github.com/EugeneDraitsev/yubikey-better-auth) - Live demo: [yubikey-better-auth.vercel.app](https://yubikey-better-auth.vercel.app/) Here’s a screen recording showing the issue: https://github.com/user-attachments/assets/4e2d2798-6a8f-41ee-ab09-737e656fe35a To work around the problem, I added the following logic to `auth.ts`: ```typescript hooks: { after: createAuthMiddleware(async (ctx) => { if (ctx.path === '/passkey/generate-register-options') { const result = ctx.context.returned as { user: { id: string; displayName: string; name?: string }; }; const modified = { ...result, user: { ...result?.user, displayName: result?.user?.displayName || result?.user?.name } }; return ctx.json(modified); } }) }, ``` Here’s a live version with the fix applied: [yubikey-better-auth-git-display-name-fix-drais-projects.vercel.app](https://yubikey-better-auth-git-display-name-fix-drais-projects.vercel.app/) And a screen recording of it working as expected: https://github.com/user-attachments/assets/cde03c05-739e-472d-b26d-b2c307d78712 It would be great to get this fix into `better-auth`, so that YubiKey USB registration works out of the box without needing custom middleware. --- <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 11:40:07 -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#4272