|
| 1 | +--- |
| 2 | +id: 7a958307-4cdb-47f3-a689-0c7de57e3ff7 |
| 3 | +blueprint: tag |
| 4 | +title: 'User:Passkey_Form' |
| 5 | +description: 'Creates a passkey registration form' |
| 6 | +intro: 'Allows authenticated users to set up passkeys' |
| 7 | +variables: |
| 8 | + - |
| 9 | + name: passkey_option_url |
| 10 | + type: string |
| 11 | + description: 'URL to fetch WebAuthn attestation options for creating a new passkey.' |
| 12 | + - |
| 13 | + name: passkey_verify_url |
| 14 | + type: string |
| 15 | + description: 'URL to store the new passkey after registration.' |
| 16 | +related_entries: |
| 17 | + - 38323438-4719-4a7b-ba5a-8abfe0d7dfc0 |
| 18 | + - d0ed4ac0-536a-47a1-965b-202b52baddb2 |
| 19 | + - 7432f1cb-7418-4d54-8e65-51b1ae3bcb3a |
| 20 | +--- |
| 21 | +## Overview |
| 22 | + |
| 23 | +The `user:passkey_form` tag provides the necessary URLs to set up passkeys for authenticated users. |
| 24 | + |
| 25 | +### JavaScript helpers |
| 26 | + |
| 27 | +You'll need to include the frontend helpers script on your page: |
| 28 | + |
| 29 | +```html |
| 30 | +<script src="/vendor/statamic/frontend/js/helpers.js"></script> |
| 31 | +``` |
| 32 | + |
| 33 | +### Example |
| 34 | + |
| 35 | +::tabs |
| 36 | + |
| 37 | +::tab antlers |
| 38 | +```antlers |
| 39 | +{{ user:passkey_form }} |
| 40 | + <input type="text" id="passkey-name" placeholder="Passkey name (e.g., My Laptop)"> |
| 41 | + <button type="button" id="create-passkey">Create Passkey</button> |
| 42 | +
|
| 43 | + <script> |
| 44 | + document.getElementById('create-passkey').addEventListener('click', () => { |
| 45 | + const name = document.getElementById('passkey-name').value || 'My Passkey'; |
| 46 | +
|
| 47 | + Statamic.$passkeys.register({ |
| 48 | + optionsUrl: '{{ passkey_option_url }}', |
| 49 | + verifyUrl: '{{ passkey_verify_url }}', |
| 50 | + name: name, |
| 51 | + onSuccess: () => location.reload(), |
| 52 | + onError: (error) => alert(error.message), |
| 53 | + // csrfToken (optional) |
| 54 | + }); |
| 55 | + }); |
| 56 | + </script> |
| 57 | +{{ /user:passkey_form }} |
| 58 | +``` |
| 59 | +::tab blade |
| 60 | +```blade |
| 61 | +<s:user:passkey_form> |
| 62 | + <input type="text" id="passkey-name" placeholder="Passkey name (e.g., My Laptop)"> |
| 63 | + <button type="button" id="create-passkey">Create Passkey</button> |
| 64 | +
|
| 65 | + <script> |
| 66 | + document.getElementById('create-passkey').addEventListener('click', () => { |
| 67 | + const name = document.getElementById('passkey-name').value || 'My Passkey'; |
| 68 | +
|
| 69 | + Statamic.$passkeys.register({ |
| 70 | + optionsUrl: '{{ $passkey_option_url }}', |
| 71 | + verifyUrl: '{{ $passkey_verify_url }}', |
| 72 | + name: name, |
| 73 | + onSuccess: () => location.reload(), |
| 74 | + onError: (error) => alert(error.message), |
| 75 | + // csrfToken (optional) |
| 76 | + }); |
| 77 | + }); |
| 78 | + </script> |
| 79 | +</s:user:passkey_form> |
| 80 | +``` |
| 81 | +:: |
0 commit comments