From 473ac3948966bec62764a6775deb626b2f5abcf3 Mon Sep 17 00:00:00 2001
From: Tanmay Deep Sharma <32020192+tds-1@users.noreply.github.com>
Date: Thu, 6 Aug 2026 16:17:58 +0530
Subject: [PATCH] feat: nudge users with a dashboard banner when backup codes
run low (#14103)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## Linear Ticket
-
https://linear.app/chatwoot/issue/CW-6884/nudge-users-with-a-dashboard-banner-when-2fa-backup-codes-run-low
## Description
Shows a dashboard-wide banner when the signed-in user has 3 or fewer
unused backup codes left (amber), turning to an alert style at 0
remaining. Clicking "Generate codes" takes the user to the MFA settings
page so they can regenerate codes before they get locked out. Inspired
by Google's post-backup-code-use nudges.
## How to test
1. Sign in as a user with MFA enabled.
2. In a Rails console, simulate a low state by marking most backup codes
as used:
```ruby
u = User.find_by(email: '')
codes = u.otp_backup_codes.dup
(0...8).each { |i| codes[i] = 'XXXXXXXX' }
u.otp_backup_codes = codes
u.save!
```
3. Reload any dashboard page — the amber banner should appear with a
"Generate codes" CTA.
4. Click the CTA — it should route to **Profile → Two-Factor
Authentication**, where you can regenerate codes.
5. Set the count to 0 (mark all 10 as `'XXXXXXXX'`) — banner should
switch to the red/alert style.
6. Regenerate codes — banner should disappear on the next dashboard page
load.
## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
> Base is the [disable-with-backup-code PR
branch](https://github.com/chatwoot/chatwoot/pull/14102) so CTAs around
recovery are consistent; rebase onto `develop` once that merges.
---------
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: iamsivin
Co-authored-by: Sony Mathew
---
app/javascript/dashboard/App.vue | 3 +
.../components/app/LowBackupCodesBanner.vue | 121 ++++++++++++++++++
.../dashboard/components/ui/Banner.vue | 1 +
.../dashboard/i18n/locale/en/mfa.json | 5 +
.../settings/profile/MfaSettings.vue | 5 +
app/javascript/shared/constants/busEvents.js | 1 +
app/services/mfa/management_service.rb | 4 +
.../api/v1/profile/mfa/show.json.jbuilder | 5 +-
8 files changed, 144 insertions(+), 1 deletion(-)
create mode 100644 app/javascript/dashboard/components/app/LowBackupCodesBanner.vue
diff --git a/app/javascript/dashboard/App.vue b/app/javascript/dashboard/App.vue
index 99aebfd1a..1a5eb2469 100644
--- a/app/javascript/dashboard/App.vue
+++ b/app/javascript/dashboard/App.vue
@@ -6,6 +6,7 @@ import UpdateBanner from './components/app/UpdateBanner.vue';
import StatusBanner from './components/app/StatusBanner.vue';
import PaymentPendingBanner from './components/app/PaymentPendingBanner.vue';
import PendingEmailVerificationBanner from './components/app/PendingEmailVerificationBanner.vue';
+import LowBackupCodesBanner from './components/app/LowBackupCodesBanner.vue';
import vueActionCable from './helper/actionCable';
import { useRouter } from 'vue-router';
import { useStore } from 'dashboard/composables/store';
@@ -32,6 +33,7 @@ export default {
PaymentPendingBanner,
WootSnackbarBox,
PendingEmailVerificationBanner,
+ LowBackupCodesBanner,
},
setup() {
const router = useRouter();
@@ -143,6 +145,7 @@ export default {
+
diff --git a/app/javascript/dashboard/components/app/LowBackupCodesBanner.vue b/app/javascript/dashboard/components/app/LowBackupCodesBanner.vue
new file mode 100644
index 000000000..6cd38f967
--- /dev/null
+++ b/app/javascript/dashboard/components/app/LowBackupCodesBanner.vue
@@ -0,0 +1,121 @@
+
+
+
+
+