mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-11 13:29:12 +00:00
feat: Add hidden input to store passkey credential data for form submission
This commit is contained in:
parent
2286708d56
commit
893631eb4c
@ -12,6 +12,7 @@ type RegisterPasskeyData struct {
|
|||||||
|
|
||||||
templ RegisterPasskey(action, method string, data RegisterPasskeyData) {
|
templ RegisterPasskey(action, method string, data RegisterPasskeyData) {
|
||||||
<form action={ templ.SafeURL(action) } method={ method }>
|
<form action={ templ.SafeURL(action) } method={ method }>
|
||||||
|
<input type="hidden" name="credential" id="credential-data" />
|
||||||
<sl-card class="card-form gap-4 max-w-lg">
|
<sl-card class="card-form gap-4 max-w-lg">
|
||||||
<div slot="header">
|
<div slot="header">
|
||||||
<div class="w-full py-1">
|
<div class="w-full py-1">
|
||||||
@ -85,8 +86,17 @@ const publicKey = {
|
|||||||
navigator.credentials
|
navigator.credentials
|
||||||
.create({ publicKey })
|
.create({ publicKey })
|
||||||
.then((newCredentialInfo) => {
|
.then((newCredentialInfo) => {
|
||||||
console.log(newCredentialInfo);
|
// Convert credential to base64 string
|
||||||
// Send new credential info to server for verification and registration.
|
const credentialJSON = JSON.stringify({
|
||||||
|
id: newCredentialInfo.id,
|
||||||
|
rawId: Array.from(new Uint8Array(newCredentialInfo.rawId)),
|
||||||
|
response: {
|
||||||
|
attestationObject: Array.from(new Uint8Array(newCredentialInfo.response.attestationObject)),
|
||||||
|
clientDataJSON: Array.from(new Uint8Array(newCredentialInfo.response.clientDataJSON))
|
||||||
|
},
|
||||||
|
type: newCredentialInfo.type
|
||||||
|
});
|
||||||
|
document.getElementById('credential-data').value = btoa(credentialJSON);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user