diff --git a/app/javascript/packs/webauthn-authenticate.ts b/app/javascript/packs/webauthn-authenticate.ts index 0932fd27211..14c4784fe57 100644 --- a/app/javascript/packs/webauthn-authenticate.ts +++ b/app/javascript/packs/webauthn-authenticate.ts @@ -4,6 +4,7 @@ function webauthn() { const webauthnInProgressContainer = document.getElementById('webauthn-auth-in-progress')!; const webauthnSuccessContainer = document.getElementById('webauthn-auth-successful')!; + const webauthAlertContainer = document.querySelector('.usa-alert--error')!; const webauthnPlatformRequested = webauthnInProgressContainer.dataset.platformAuthenticatorRequested === 'true'; const multipleFactorsEnabled = @@ -35,6 +36,10 @@ function webauthn() { (document.getElementById('signature') as HTMLInputElement).value = result.signature; webauthnInProgressContainer.classList.add('display-none'); webauthnSuccessContainer.classList.remove('display-none'); + // Check if alert container is shown and remove when device passes successfully. + if (webauthAlertContainer) { + webauthAlertContainer.remove(); + } }) .catch((error: Error) => { (document.getElementById('webauthn_error') as HTMLInputElement).value = error.name; diff --git a/spec/features/webauthn/sign_in_spec.rb b/spec/features/webauthn/sign_in_spec.rb index 723ea04c0fc..4ddeebba9a1 100644 --- a/spec/features/webauthn/sign_in_spec.rb +++ b/spec/features/webauthn/sign_in_spec.rb @@ -49,4 +49,19 @@ expect(page).to have_content(t('errors.general')) expect(page).to have_current_path(login_two_factor_webauthn_path) end + + it 'does not show error after successful challenge/secret reattempt' do + mock_webauthn_verification_challenge + + sign_in_user(webauthn_configuration.user) + # click the next button or cancel from the browser dialog + click_button t('forms.buttons.continue') + + expect(page).to have_content(t('errors.general')) + + mock_press_button_on_hardware_key_on_verification + click_button t('forms.buttons.continue') + + expect(page).to_not have_content(t('errors.general')) + end end