Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds passkey support to the
{{ user:login_form }}and adds various other tags for setting up and managing passkeys from the frontend.Tags
{{ user:login_form }}To support passkeys on your login page, you will need to include the helpers script on your page:
Then, you may combine the JS helpers & variables from the tag to add passkey support.
{{ user:login_form }} <!-- ... --> {{ if passkeys_enabled }} <button type="button" id="passkey-login">Login with Passkey</button> <script> document.getElementById('passkey-login').addEventListener('click', () => { Statamic.$passkeys.authenticate({ optionsUrl: '{{ passkey_options_url }}', verifyUrl: '{{ passkey_verify_url }}', onSuccess: (data) => window.location = data.redirect || '/', onError: (error) => alert(error.message) }); }); // Enable browser autofill for passkeys Statamic.$passkeys.initAutofill({ optionsUrl: '{{ passkey_options_url }}', verifyUrl: '{{ passkey_verify_url }}', onSuccess: (data) => window.location = data.redirect || '/' }); </script> {{ /if }} {{ /user:login_form }}Important
For browser autofill to work, your email input must have
autocomplete="username webauthn".{{ user:passkey_form }}The passkey form allows you to create passkeys from the frontend.
{{ user:passkey_form }} <input type="text" id="passkey-name" placeholder="Passkey name (e.g., My Laptop)"> <button type="button" id="create-passkey">Create Passkey</button> {{ if success }} <p>Passkey created successfully!</p> {{ /if }} {{ if errors }} <ul> {{ errors }} <li>{{ value }}</li> {{ /errors }} </ul> {{ /if }} <script> document.getElementById('create-passkey').addEventListener('click', () => { const name = document.getElementById('passkey-name').value || 'My Passkey'; Statamic.$passkeys.register({ optionsUrl: '{{ create_url }}', verifyUrl: '{{ store_url }}', name: name, onSuccess: () => location.reload(), onError: (error) => alert(error.message) }); }); </script> {{ /user:passkey_form }}{{ user:passkeys }}This tag allows you to loop through your passkeys.
{{ user:passkeys as="passkeys" }} {{ if passkeys }} <h3>Your Passkeys</h3> <ul> {{ passkeys }} <li> <strong>{{ name }}</strong> {{ if last_login }} <span>Last used: {{ last_login format="M j, Y g:i A" }}</span> {{ else }} <span>Never used</span> {{ /if }} {{ user:delete_passkey_form :id="id" }} <button type="submit" onclick="return confirm('Delete this passkey?')"> Delete </button> {{ /user:delete_passkey_form }} </li> {{ /passkeys }} </ul> {{ else }} <p>You haven't set up any passkeys yet.</p> {{ /if }} {{ /user:passkeys }}Variables:
id- Passkey identifiername- User-defined passkey namelast_login- Last time the passkey was useddelete_url- URL to delete this passkey{{ user:delete_passkey_form }}This tag renders a form to delete a passkey. Most useful inside a
{{ user:passkeys }}loop.{{ user:delete_passkey_form :id="id" }} <button type="submit">Delete</button> {{ /user:delete_passkey_form }}Statamic.$passkeysJavaScript APIThe frontend helpers script (
/vendor/statamic/frontend/js/helpers.js) now exposesStatamic.$passkeyswith:authenticate(options)- Login with a passkeyregister(options)- Register a new passkeyinitAutofill(options)- Enable browser autofill for passkeyscancel()- Cancel in-progress operationssupported- Browser support checkDocs PR: TODO