Passkey
A passwordless sign-in button with passkeys, and the list of an account's passkeys.
zb:passkey-button · zb:passkey-list zubazar/ui · free (MIT)
Signing in with a passkey
The button gets the options from options-url, opens the browser's dialog and sends the answer to action-url.
<zb:passkey-button
mode="login"
options-url="{{ route('passkeys.login.options') }}"
action-url="{{ route('passkeys.login') }}"
class="w-full"
/>
| Prop | Values |
|---|---|
options-url | The address that returns the WebAuthn options |
action-url | The address that checks the answer |
options-get | Fetches the options with GET |
Adding a passkey to the account (Livewire)
In Livewire give methods instead of addresses: options-method returns the options and action-method takes the answer and the name in name-field.
<zb:input id="passkey-name" label="Name of this device" placeholder="Work laptop" />
<zb:passkey-button
mode="register"
options-method="passkeyOptions"
action-method="addPasskey"
name-field="#passkey-name"
/>
| Prop | Values |
|---|---|
mode | login (default) · register |
options-method | The Livewire method that returns the options |
action-method | The Livewire method that receives the answer and the name |
name-field | The selector of the field the name is read from |
List of passkeys
Lists the account's passkeys with their name, date added and last use; remove adds a Remove button to each row.
<zb:passkey-list remove="removePasskey" :passkeys="[
['id' => 1, 'name' => 'MacBook Pro', 'created_at' => now()->subMonths(3), 'last_used_at' => now()->subDay()],
['id' => 2, 'name' => 'iPhone', 'created_at' => now()->subWeeks(2), 'last_used_at' => null],
]" />
| Prop | Values |
|---|---|
passkeys | List: id, name, created_at, last_used_at |
remove | The remove method (called with the id) |
Empty list
With no passkeys yet a general text shows; a slot, when given, is shown instead.
<zb:passkey-list>Add a passkey to sign in without typing a password.</zb:passkey-list>
About
The kit does only the browser side (navigator.credentials). Creating the WebAuthn options and verifying the browser's answer is your application's code, written with a WebAuthn library.
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
passkey-button: mode | — | login | login · register |
passkey-button: options-url / action-url | — | null | The application's two steps (JSON, POST, CSRF) |
passkey-button: options-method / action-method | — | null | The same steps as Livewire methods |
passkey-button: options-get | boolean | false | Fetches the options with GET |
passkey-button: name-field | — | null | register: the selector of the field the name is read from |
passkey-button: label | — | null | Default: Sign in with a passkey / Add a passkey |
passkey-button: variant, size | — | secondary, md | The same as zb:button |
passkey-list: passkeys | — | [] | id, name, created_at, last_used_at |
passkey-list: remove | — | null | The remove method; without it no button is drawn |
passkey-list: remove-confirmation | — | null | The text of the remove confirmation |
Slots: passkey-list: the default slot is shown while the list is empty.
Advanced
Events
After success the button sends zb:passkey:done, after a failure zb:passkey:failed. For example, refresh the component to show the new passkey in the list.
<div x-on:zb:passkey:done="$wire.$refresh()">
<zb:passkey-button mode="register" options-method="passkeyOptions" action-method="addPasskey" />
</div>
Developer notes
- Requests go as JSON
POSTwith the<meta name="csrf-token">header; addoptions-getto fetch the options withGET. - If the answer has
{ "redirect": "/panel" }, the page goes there. - If the user closes the browser's dialog, no message shows; if the server returns an error, its
messageor a general message shows below the button. - Check the signed-in user on the server in the Livewire methods.
- Each list item can be an array or a model (
id,name,created_at,last_used_at); date objects are written in the page's language, text dates as they are. - After confirmation the Remove button calls the
removemethod with the record'sid.
Events
| Event | detail | Description |
|---|---|---|
zb:passkey:done | { mode, result } | Sent from the button after success; it bubbles. mode is register or login; result is the server answer, or null. |
zb:passkey:failed | { mode, error, message, status } | Sent from the button on failure, including when the user cancels (error is NotAllowedError or AbortError). status is the HTTP status or null. |