From beb8c80787beadbfdb8b970368a3200f7d59f58e Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 20 Mar 2024 23:59:37 +0100 Subject: Replace a bunch of `let` with `const` According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const > Many style guides (including MDN's) recommend using const over let whenever a variable is not reassigned in its scope. This makes the intent clear that a variable's type (or value, in the case of a primitive) can never change. --- internal/ui/static/js/webauthn_handler.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'internal/ui/static/js/webauthn_handler.js') diff --git a/internal/ui/static/js/webauthn_handler.js b/internal/ui/static/js/webauthn_handler.js index 0835ae0d..32752d54 100644 --- a/internal/ui/static/js/webauthn_handler.js +++ b/internal/ui/static/js/webauthn_handler.js @@ -5,7 +5,7 @@ class WebAuthnHandler { static showErrorMessage(errorMessage) { console.log("webauthn error: " + errorMessage); - let alertElement = document.getElementById("webauthn-error"); + const alertElement = document.getElementById("webauthn-error"); if (alertElement) { alertElement.textContent += " (" + errorMessage + ")"; alertElement.classList.remove("hidden"); @@ -79,14 +79,14 @@ class WebAuthnHandler { return; } - let credentialCreationOptions = await registerBeginResponse.json(); + const credentialCreationOptions = await registerBeginResponse.json(); credentialCreationOptions.publicKey.challenge = this.decodeBuffer(credentialCreationOptions.publicKey.challenge); credentialCreationOptions.publicKey.user.id = this.decodeBuffer(credentialCreationOptions.publicKey.user.id); if (Object.hasOwn(credentialCreationOptions.publicKey, 'excludeCredentials')) { credentialCreationOptions.publicKey.excludeCredentials.forEach((credential) => credential.id = this.decodeBuffer(credential.id)); } - let attestation = await navigator.credentials.create(credentialCreationOptions); + const attestation = await navigator.credentials.create(credentialCreationOptions); let registrationFinishResponse; try { @@ -108,7 +108,7 @@ class WebAuthnHandler { throw new Error("Login failed with HTTP status code " + response.status); } - let jsonData = await registrationFinishResponse.json(); + const jsonData = await registrationFinishResponse.json(); window.location.href = jsonData.redirect; } @@ -121,7 +121,7 @@ class WebAuthnHandler { return; } - let credentialRequestOptions = await loginBeginResponse.json(); + const credentialRequestOptions = await loginBeginResponse.json(); credentialRequestOptions.publicKey.challenge = this.decodeBuffer(credentialRequestOptions.publicKey.challenge); if (Object.hasOwn(credentialRequestOptions.publicKey, 'allowCredentials')) { -- cgit v1.2.3