v0.0.2
Demos (demo panel, opens in a new tab)

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

BLADE

The button gets the options from options-url, opens the browser's dialog and sends the answer to action-url.

blade
<zb:passkey-button
    mode="login"
    options-url="{{ route('passkeys.login.options') }}"
    action-url="{{ route('passkeys.login') }}"
    class="w-full"
/>
PropValues
options-urlThe address that returns the WebAuthn options
action-urlThe address that checks the answer
options-getFetches the options with GET

Adding a passkey to the account (Livewire)

BLADE

In Livewire give methods instead of addresses: options-method returns the options and action-method takes the answer and the name in name-field.

blade
<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"
/>
PropValues
modelogin (default) · register
options-methodThe Livewire method that returns the options
action-methodThe Livewire method that receives the answer and the name
name-fieldThe selector of the field the name is read from

List of passkeys

List of passkeys: view
BLADE

Lists the account's passkeys with their name, date added and last use; remove adds a Remove button to each row.

blade
<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],
]" />
PropValues
passkeysList: id, name, created_at, last_used_at
removeThe remove method (called with the id)

Empty list

Empty list: view
BLADE

With no passkeys yet a general text shows; a slot, when given, is shown instead.

blade
<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?

PropTypeDefaultDescription
passkey-button: mode—loginlogin · register
passkey-button: options-url / action-url—nullThe application's two steps (JSON, POST, CSRF)
passkey-button: options-method / action-method—nullThe same steps as Livewire methods
passkey-button: options-getbooleanfalseFetches the options with GET
passkey-button: name-field—nullregister: the selector of the field the name is read from
passkey-button: label—nullDefault: Sign in with a passkey / Add a passkey
passkey-button: variant, size—secondary, mdThe same as zb:button
passkey-list: passkeys—[]id, name, created_at, last_used_at
passkey-list: remove—nullThe remove method; without it no button is drawn
passkey-list: remove-confirmation—nullThe text of the remove confirmation

Slots: passkey-list: the default slot is shown while the list is empty.

Advanced

1 example

Events

BLADE

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.

blade
<div x-on:zb:passkey:done="$wire.$refresh()">
    <zb:passkey-button mode="register" options-method="passkeyOptions" action-method="addPasskey" />
</div>

Developer notes

Events, hooks and details
  • Requests go as JSON POST with the <meta name="csrf-token"> header; add options-get to fetch the options with GET.
  • 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 message or 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 remove method with the record's id.

Events

EventdetailDescription
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.
Zubazar UI · ZubazarDesigned for people.