Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
document.getElementById('login').addEventListener('submit', function(event) {
event.preventDefault();
return getGetAssertionChallenge()
.then((getAssertionChallenge) => {
/*{
"challenge": "Ld0vp5byLeFZBOpclgKP3BEc8AA4aBewYPlwbkgLh98",
"status": "ok"
}*/
getAssertionChallenge = preformatGetAssertReq(getAssertionChallenge);
return navigator.credentials.get({ 'publicKey': getAssertionChallenge })
})
.then((newCredentialInfo) => {
newCredentialInfo = publicKeyCredentialToJSON(newCredentialInfo)
return getAssertionResponse(newCredentialInfo)
})
.then((serverResponse) => {
if(serverResponse.status !== 'ok')
throw new Error('Error registering user! Server returned: ' + serverResponse.errorMessage);
alert('Success!');
})
.catch((error) => {
alert('FAIL' + error)
console.log('FAIL', error)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment