diff --git a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs
index 5f9e4f025c5..9e709d1ed2d 100644
--- a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs
+++ b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs
@@ -26,11 +26,15 @@
{{#if this.showSecondFactorKey}}
- {{this.secondFactorKey}}
+
+ {{this.secondFactorKey}}
+
{{else}}
- {{i18n
- "user.second_factor.show_key_description"
- }}
+ {{i18n "user.second_factor.show_key_description"}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js
index 0a254e8c4e0..5a7281c6d40 100644
--- a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js
+++ b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js
@@ -33,7 +33,9 @@ export default class SecondFactorAddTotp extends Component {
}
@action
- enableShowSecondFactorKey() {
+ enableShowSecondFactorKey(e) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
this.showSecondFactorKey = true;
}
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js
index 16aa5b2cdbf..603cb13eefb 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js
@@ -66,8 +66,13 @@ acceptance("User Preferences - Second Factor", function (needs) {
await click(".new-totp");
assert.ok(exists(".qr-code img"), "shows qr code image");
- await click(".add-totp");
+ await click(".modal a.show-second-factor-key");
+ assert.ok(
+ exists(".modal .second-factor-key"),
+ "displays second factor key"
+ );
+ await click(".add-totp");
assert.ok(
query(".alert-error").innerHTML.includes("provide a name and the code"),
"shows name/token missing error message"