From af23fec835f2cabb76bb27dadd5c614dc89762f2 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Mon, 11 Dec 2023 10:56:30 -0500 Subject: [PATCH] FIX: Reload page after adding 2FA when it is enforced (#24803) When 2FA is enforced and the user has no key or TOTP on their account, we block navigating away from the page until they have added one. However, we don't reload the page after they have added one, so the user is left with a page that still says they need to add 2FA. --- .../app/components/modal/second-factor-add-security-key.js | 3 +++ .../discourse/app/components/modal/second-factor-add-totp.js | 3 +++ .../discourse/app/controllers/preferences/second-factor.js | 2 ++ 3 files changed, 8 insertions(+) diff --git a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-security-key.js b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-security-key.js index 444ea33828d..7ce121f3aca 100644 --- a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-security-key.js +++ b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-security-key.js @@ -130,6 +130,9 @@ export default class SecondFactorAddSecurityKey extends Component { this.args.model.markDirty(); this.errorMessage = null; this.args.closeModal(); + if (this.args.model.enforcedSecondFactor) { + window.location.reload(); + } }) .catch((error) => this.args.model.onError(error)) .finally(() => (this.loading = false)); 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 2b8979349a5..3d86c5c8149 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 @@ -61,6 +61,9 @@ export default class SecondFactorAddTotp extends Component { this.args.model.markDirty(); this.errorMessage = null; this.args.closeModal(); + if (this.args.model.enforcedSecondFactor) { + window.location.reload(); + } }) .catch((error) => this.args.model.onError(error)) .finally(() => (this.loading = false)); 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 53a27644b8c..6486cfe82f3 100644 --- a/app/assets/javascripts/discourse/app/controllers/preferences/second-factor.js +++ b/app/assets/javascripts/discourse/app/controllers/preferences/second-factor.js @@ -53,6 +53,7 @@ export default Controller.extend(CanCheckEmails, { await this.modal.show(SecondFactorAddTotp, { model: { secondFactor: this.model, + enforcedSecondFactor: this.currentUser.enforcedSecondFactor, markDirty: () => this.markDirty(), onError: (e) => this.handleError(e), }, @@ -68,6 +69,7 @@ export default Controller.extend(CanCheckEmails, { await this.modal.show(SecondFactorAddSecurityKey, { model: { secondFactor: this.model, + enforcedSecondFactor: this.currentUser.enforcedSecondFactor, markDirty: this.markDirty, onError: this.handleError, },