From d7c2a2951c6a0a85f43675c83d3d639cd50eccb4 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 15 Jan 2022 16:52:56 +0000 Subject: Webauthn nits (#18284) This contains some additional fixes and small nits related to #17957 Signed-off-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang --- web_src/js/features/user-auth-webauthn.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'web_src') diff --git a/web_src/js/features/user-auth-webauthn.js b/web_src/js/features/user-auth-webauthn.js index 5b580e7949..bc221d037f 100644 --- a/web_src/js/features/user-auth-webauthn.js +++ b/web_src/js/features/user-auth-webauthn.js @@ -24,7 +24,7 @@ export function initUserAuthWebAuthn() { .then((credential) => { verifyAssertion(credential); }).catch((err) => { - webAuthnError(0, err.message); + webAuthnError('general', err.message); }); }).fail(() => { webAuthnError('unknown'); @@ -113,11 +113,16 @@ function webauthnRegistered(newCredential) { function webAuthnError(errorType, message) { $('#webauthn-error [data-webauthn-error-msg]').hide(); - if (errorType === 0 && message && message.length > 1) { - $(`#webauthn-error [data-webauthn-error-msg=0]`).text(message); - $(`#webauthn-error [data-webauthn-error-msg=0]`).show(); + const $errorGeneral = $(`#webauthn-error [data-webauthn-error-msg=general]`); + if (errorType === 'general') { + $errorGeneral.show().text(message || 'unknown error'); } else { - $(`#webauthn-error [data-webauthn-error-msg=${errorType}]`).show(); + const $errorTyped = $(`#webauthn-error [data-webauthn-error-msg=${errorType}]`); + if ($errorTyped.length) { + $errorTyped.show(); + } else { + $errorGeneral.show().text(`unknown error type: ${errorType}`); + } } $('#webauthn-error').modal('show'); } @@ -149,7 +154,6 @@ export function initUserAuthWebAuthnRegister() { return; } - $('#register-device').modal({allowMultiple: false}); $('#webauthn-error').modal({allowMultiple: false}); $('#register-webauthn').on('click', (e) => { e.preventDefault(); @@ -167,7 +171,6 @@ function webAuthnRegisterRequest() { name: $('#nickname').val(), }).done((makeCredentialOptions) => { $('#nickname').closest('div.field').removeClass('error'); - $('#register-device').modal('show'); makeCredentialOptions.publicKey.challenge = decode(makeCredentialOptions.publicKey.challenge); makeCredentialOptions.publicKey.user.id = decode(makeCredentialOptions.publicKey.user.id); @@ -185,7 +188,7 @@ function webAuthnRegisterRequest() { webAuthnError('unknown'); return; } - webAuthnError(0, err); + webAuthnError('general', err.message); }); }).fail((xhr) => { if (xhr.status === 409) { -- cgit v1.2.3