Installation
1
Install the package
2
Add the server plugin
Import
passkey from @better-auth/passkey and add it to your plugins list:auth.ts
3
Run the database migration
The passkey plugin needs a
passkey table in your database:- migrate
- generate
4
Add the client plugin
Import
passkeyClient from @better-auth/passkey/client:auth-client.ts
Usage
Register a passkey
A user must be signed in before they can register a passkey. Callpasskey.addPasskey:
register-passkey.ts
Sign in with a passkey
CallsignIn.passkey to prompt the user to authenticate:
sign-in.ts
Browser autofill (Conditional UI)
Conditional UI lets the browser automatically suggest passkeys in input fields. Two things are required:1
Add autocomplete attributes to inputs
Add
webauthn as the last value of the autocomplete attribute on your input fields:2
Call signIn.passkey with autoFill on mount
sign-in.tsx
List passkeys
list-passkeys.ts
Delete a passkey
delete-passkey.ts
Update a passkey name
update-passkey.ts
Relying party configuration
Configure the relying party (RP) options in thepasskey() plugin:
auth.ts
During local development you can omit
rpID, rpName, and origin. Better Auth defaults to localhost.