feat(passkey): allow custom passkey name during registration (#3587)

* feat(passkey): allow custom passkey name during registration

* lint

* docs: specify name prop in passkey docs

* chore: add changeset

* chore: changeset

* chore: update changeset

* remove changest

---------

Co-authored-by: Bereket Engida <86073083+Bekacru@users.noreply.github.com>
This commit is contained in:
Marti
2025-08-01 19:43:35 +03:00
committed by GitHub
parent 7fa90f8d4d
commit e5f3f31311
4 changed files with 19 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"better-auth": patch
---
feat(passkey): allow custom passkey name during registration

View File

@@ -95,6 +95,10 @@ To add or register a passkey make sure a user is authenticated and then call the
<APIMethod path="/passkey/add-passkey" method="POST" isClientOnly>
```ts
type addPasskey = {
/**
* An optional name to label the authenticator account being registered. If not provided, it will default to the user's email address or user ID
*/
name?: string = "example-passkey-name"
/**
* You can also specify the type of authenticator you want to register. Default behavior allows both platform and cross-platform passkeys
*/

View File

@@ -106,6 +106,9 @@ export const getPasskeyActions = (
...(opts?.authenticatorAttachment && {
authenticatorAttachment: opts.authenticatorAttachment,
}),
...(opts?.name && {
name: opts.name,
}),
},
},
);

View File

@@ -133,6 +133,7 @@ export const passkey = (options?: PasskeyOptions) => {
authenticatorAttachment: z
.enum(["platform", "cross-platform"])
.optional(),
name: z.string().optional(),
})
.optional(),
metadata: {
@@ -150,6 +151,11 @@ export const passkey = (options?: PasskeyOptions) => {
"cross-platform" for authenticators that can be used across devices.`,
required: false,
},
name: {
description: `Optional custom name for the passkey.
This can help identify the passkey when managing multiple credentials.`,
required: false,
},
},
},
content: {
@@ -271,7 +277,7 @@ export const passkey = (options?: PasskeyOptions) => {
rpName: opts.rpName || ctx.context.appName,
rpID: getRpID(opts, ctx.context.options.baseURL),
userID,
userName: session.user.email || session.user.id,
userName: ctx.query?.name || session.user.email || session.user.id,
userDisplayName: session.user.email || session.user.id,
attestationType: "none",
excludeCredentials: userPasskeys.map((passkey) => ({