Skip to content

Commit

Permalink
fix: catch fetch error during webauthn authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
rdubigny committed Feb 7, 2025
1 parent 367f2c7 commit 99bc601
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions assets/js/webauthn-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ document.addEventListener(
errorElement.innerText = "";
beginElement.disabled = true;

// GET registration options from the endpoint that calls
// @simplewebauthn/server -> generateRegistrationOptions()
const authOptions = await fetch(authOptionsUrl);

let asseResp;

try {
// GET registration options from the endpoint that calls
// @simplewebauthn/server -> generateRegistrationOptions()
const authOptions = await fetch(authOptionsUrl);

// Pass the options to the authenticator and wait for a response
asseResp = await startAuthentication(await authOptions.json());
} catch (error) {
Expand Down Expand Up @@ -66,8 +67,9 @@ document.addEventListener(
const hasNotification = urlParams.get("notification") !== null;

if (!hasNotification) {
const authOptions = await fetch(authOptionsUrl);
try {
const authOptions = await fetch(authOptionsUrl);

let asseResp = await startAuthentication(
await authOptions.json(),
true,
Expand All @@ -78,6 +80,7 @@ document.addEventListener(
authenticationResponseForm.requestSubmit();
} catch (e) {
// fail silently
console.error(e);
}
}
};
Expand Down
9 changes: 5 additions & 4 deletions assets/js/webauthn-registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ document.addEventListener(
clearDisplay();
beginElement.disabled = true;

// GET registration options from the endpoint that calls
// @simplewebauthn/server -> generateRegistrationOptions()
const resp = await fetch("/api/webauthn/generate-registration-options");

let attResp;

try {
// GET registration options from the endpoint that calls
// @simplewebauthn/server -> generateRegistrationOptions()
const resp = await fetch("/api/webauthn/generate-registration-options");

// Pass the options to the authenticator and wait for a response
attResp = await startRegistration(await resp.json());
} catch (error) {
Expand Down

0 comments on commit 99bc601

Please sign in to comment.