in frontend/passkeys.js [28:52]
export async function authenticatePasskey(targetHref, csrfToken) {
console.log("starting authentication");
const authOptionsResponse = await fetch("/passkey/auth-options");
const publicKeyCredentialRequestOptionsJSON = await authOptionsResponse.json();
const credentialGetOptions = PublicKeyCredential.parseRequestOptionsFromJSON(publicKeyCredentialRequestOptionsJSON);
const publicKeyCredential = await navigator.credentials.get({ publicKey: credentialGetOptions});
console.log("publicKeyCredential: ", publicKeyCredential);
// Add a form to the DOM so that it can be submitted at page level
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', targetHref);
const credsInput = document.createElement('input');
credsInput.setAttribute('type','hidden');
credsInput.setAttribute('name','credentials');
credsInput.setAttribute('value', JSON.stringify(publicKeyCredential.toJSON()));
const csrfTokenInput = document.createElement('input');
csrfTokenInput.setAttribute('type','hidden');
csrfTokenInput.setAttribute('name','csrfToken');
csrfTokenInput.setAttribute('value', csrfToken);
form.appendChild(credsInput);
form.appendChild(csrfTokenInput);
document.getElementsByTagName('body')[0].appendChild(form);
form.submit();
}