diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/second-factor.js b/app/assets/javascripts/discourse/app/controllers/preferences/second-factor.js
index 5025c862afd..a63ab61d520 100644
--- a/app/assets/javascripts/discourse/app/controllers/preferences/second-factor.js
+++ b/app/assets/javascripts/discourse/app/controllers/preferences/second-factor.js
@@ -166,40 +166,61 @@ export default Controller.extend(CanCheckEmails, {
confirmButtonIcon: "ban",
cancelButtonClass: "btn-flat",
didConfirm: () => {
- this.currentUser
- .updateSecondFactor(
- secondFactorMethod.id,
- secondFactorMethod.name,
- true,
- secondFactorMethod.method
- )
- .then((response) => {
- if (response.error) {
- return;
- }
- this.markDirty();
- })
- .catch((e) => this.handleError(e))
- .finally(() => {
- this.setProperties({
- totps: this.totps.filter(
- (totp) =>
- totp.id !== secondFactorMethod.id ||
- totp.method !== secondFactorMethod.method
- ),
- security_keys: this.security_keys.filter(
- (key) =>
- key.id !== secondFactorMethod.id ||
- key.method !== secondFactorMethod.method
- ),
+ if (this.totps.includes(secondFactorMethod)) {
+ this.currentUser
+ .updateSecondFactor(
+ secondFactorMethod.id,
+ secondFactorMethod.name,
+ true,
+ secondFactorMethod.method
+ )
+ .then((response) => {
+ if (response.error) {
+ return;
+ }
+ this.markDirty();
+ this.set(
+ "totps",
+ this.totps.filter(
+ (totp) =>
+ totp.id !== secondFactorMethod.id ||
+ totp.method !== secondFactorMethod.method
+ )
+ );
+ })
+ .catch((e) => this.handleError(e))
+ .finally(() => {
+ this.set("loading", false);
});
+ }
- this.set("loading", false);
- });
+ if (this.security_keys.includes(secondFactorMethod)) {
+ this.currentUser
+ .updateSecurityKey(
+ secondFactorMethod.id,
+ secondFactorMethod.name,
+ true
+ )
+ .then((response) => {
+ if (response.error) {
+ return;
+ }
+ this.markDirty();
+ this.set(
+ "security_keys",
+ this.security_keys.filter(
+ (securityKey) => securityKey.id !== secondFactorMethod.id
+ )
+ );
+ })
+ .catch((e) => this.handleError(e))
+ .finally(() => {
+ this.set("loading", false);
+ });
+ }
},
});
},
-
disableSecondFactorBackup() {
this.dialog.deleteConfirm({
title: I18n.t("user.second_factor.delete_backup_codes_confirm_title"),
diff --git a/app/assets/javascripts/discourse/app/controllers/second-factor-edit-security-key.js b/app/assets/javascripts/discourse/app/controllers/second-factor-edit-security-key.js
index 352fc5bbf31..5660441c412 100644
--- a/app/assets/javascripts/discourse/app/controllers/second-factor-edit-security-key.js
+++ b/app/assets/javascripts/discourse/app/controllers/second-factor-edit-security-key.js
@@ -3,25 +3,6 @@ import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, {
actions: {
- disableSecurityKey() {
- this.user
- .updateSecurityKey(this.model.id, this.model.name, true)
- .then((response) => {
- if (response.error) {
- return;
- }
- this.markDirty();
- })
- .catch((error) => {
- this.send("closeModal");
- this.onError(error);
- })
- .finally(() => {
- this.set("loading", false);
- this.send("closeModal");
- });
- },
-
editSecurityKey() {
this.user
.updateSecurityKey(this.model.id, this.model.name, false)
diff --git a/app/assets/javascripts/discourse/app/templates/modal/second-factor-edit-security-key.hbs b/app/assets/javascripts/discourse/app/templates/modal/second-factor-edit-security-key.hbs
index 47e35776280..0dd55115418 100644
--- a/app/assets/javascripts/discourse/app/templates/modal/second-factor-edit-security-key.hbs
+++ b/app/assets/javascripts/discourse/app/templates/modal/second-factor-edit-security-key.hbs
@@ -15,11 +15,4 @@
@class="btn-primary"
@label="user.second_factor.security_key.save"
/>
-