summaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-01-15 16:52:56 +0000
committerGitHub <noreply@github.com>2022-01-15 17:52:56 +0100
commitd7c2a2951c6a0a85f43675c83d3d639cd50eccb4 (patch)
tree52d4147b19fa6615f76fb3b8e8fadef948c5bd89 /web_src
parente239d354c9bd80cdc1606dabd7a4de62708b742e (diff)
downloadgitea-d7c2a2951c6a0a85f43675c83d3d639cd50eccb4.tar.gz
gitea-d7c2a2951c6a0a85f43675c83d3d639cd50eccb4.zip
Webauthn nits (#18284)
This contains some additional fixes and small nits related to #17957 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/features/user-auth-webauthn.js19
1 files changed, 11 insertions, 8 deletions
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) {