mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-23 23:52:05 -05:00
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:
5
.changeset/curly-kids-film.md
Normal file
5
.changeset/curly-kids-film.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"better-auth": patch
|
||||
---
|
||||
|
||||
feat(passkey): allow custom passkey name during registration
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -106,6 +106,9 @@ export const getPasskeyActions = (
|
||||
...(opts?.authenticatorAttachment && {
|
||||
authenticatorAttachment: opts.authenticatorAttachment,
|
||||
}),
|
||||
...(opts?.name && {
|
||||
name: opts.name,
|
||||
}),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
Reference in New Issue
Block a user