## 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. <img width="1512" height="824" alt="Screenshot 2026-08-05 at 4 52 15 PM" src="https://github.com/user-attachments/assets/08138f3e-cc15-451e-bbcc-7772dc2a875c" /> <img width="1507" height="701" alt="Screenshot 2026-08-05 at 4 54 02 PM" src="https://github.com/user-attachments/assets/580051fa-cbb5-47c1-81a3-258b7c5b5a03" /> 2. In a Rails console, simulate a low state by marking most backup codes as used: ```ruby u = User.find_by(email: '<your user>') 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 <iamsivin@gmail.com> Co-authored-by: Sony Mathew <sony@chatwoot.com>
176 lines
5.2 KiB
Vue
176 lines
5.2 KiB
Vue
<script>
|
|
import { mapGetters } from 'vuex';
|
|
import LoadingState from './components/widgets/LoadingState.vue';
|
|
import NetworkNotification from './components/NetworkNotification.vue';
|
|
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';
|
|
import WootSnackbarBox from './components/SnackbarContainer.vue';
|
|
import { setColorTheme } from './helper/themeHelper';
|
|
import { isOnOnboardingView } from 'v3/helpers/RouteHelper';
|
|
import { useAccount } from 'dashboard/composables/useAccount';
|
|
import { useFontSize } from 'dashboard/composables/useFontSize';
|
|
import {
|
|
registerSubscription,
|
|
verifyServiceWorkerExistence,
|
|
} from './helper/pushHelper';
|
|
import ReconnectService from 'dashboard/helper/ReconnectService';
|
|
import { useUISettings } from 'dashboard/composables/useUISettings';
|
|
|
|
export default {
|
|
name: 'App',
|
|
|
|
components: {
|
|
LoadingState,
|
|
NetworkNotification,
|
|
UpdateBanner,
|
|
StatusBanner,
|
|
PaymentPendingBanner,
|
|
WootSnackbarBox,
|
|
PendingEmailVerificationBanner,
|
|
LowBackupCodesBanner,
|
|
},
|
|
setup() {
|
|
const router = useRouter();
|
|
const store = useStore();
|
|
const { accountId } = useAccount();
|
|
// Use the font size composable (it automatically sets up the watcher)
|
|
const { currentFontSize } = useFontSize();
|
|
const { uiSettings } = useUISettings();
|
|
|
|
return {
|
|
router,
|
|
store,
|
|
currentAccountId: accountId,
|
|
currentFontSize,
|
|
uiSettings,
|
|
};
|
|
},
|
|
data() {
|
|
return {
|
|
latestChatwootVersion: null,
|
|
reconnectService: null,
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters({
|
|
getAccount: 'accounts/getAccount',
|
|
isRTL: 'accounts/isRTL',
|
|
currentUser: 'getCurrentUser',
|
|
authUIFlags: 'getAuthUIFlags',
|
|
}),
|
|
hideOnOnboardingView() {
|
|
return !isOnOnboardingView(this.$route);
|
|
},
|
|
},
|
|
|
|
watch: {
|
|
currentAccountId: {
|
|
immediate: true,
|
|
handler() {
|
|
if (this.currentAccountId) {
|
|
this.initializeAccount();
|
|
}
|
|
},
|
|
},
|
|
},
|
|
mounted() {
|
|
this.initializeColorTheme();
|
|
this.listenToThemeChanges();
|
|
// If user locale is set, use it; otherwise use account locale
|
|
this.setLocale(
|
|
this.uiSettings?.locale || window.chatwootConfig.selectedLocale
|
|
);
|
|
},
|
|
unmounted() {
|
|
if (this.reconnectService) {
|
|
this.reconnectService.disconnect();
|
|
}
|
|
},
|
|
methods: {
|
|
initializeColorTheme() {
|
|
setColorTheme(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
},
|
|
listenToThemeChanges() {
|
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
mql.onchange = e => setColorTheme(e.matches);
|
|
},
|
|
setLocale(locale) {
|
|
if (locale) {
|
|
this.$root.$i18n.locale = locale;
|
|
}
|
|
},
|
|
async initializeAccount() {
|
|
await this.$store.dispatch('accounts/get');
|
|
this.$store.dispatch('setActiveAccount', {
|
|
accountId: this.currentAccountId,
|
|
});
|
|
const account = this.getAccount(this.currentAccountId);
|
|
const { locale, latest_chatwoot_version: latestChatwootVersion } =
|
|
account;
|
|
const { pubsub_token: pubsubToken } = this.currentUser || {};
|
|
// If user locale is set, use it; otherwise use account locale
|
|
this.setLocale(this.uiSettings?.locale || locale);
|
|
this.latestChatwootVersion = latestChatwootVersion;
|
|
vueActionCable.init(this.store, pubsubToken);
|
|
this.reconnectService = new ReconnectService(this.store, this.router);
|
|
window.reconnectService = this.reconnectService;
|
|
|
|
verifyServiceWorkerExistence(registration =>
|
|
registration.pushManager.getSubscription().then(subscription => {
|
|
if (subscription) {
|
|
registerSubscription();
|
|
}
|
|
})
|
|
);
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
v-if="!authUIFlags.isFetching"
|
|
id="app"
|
|
class="flex flex-col w-full h-screen min-h-0 bg-n-background"
|
|
:dir="isRTL ? 'rtl' : 'ltr'"
|
|
>
|
|
<UpdateBanner :latest-chatwoot-version="latestChatwootVersion" />
|
|
<StatusBanner />
|
|
<template v-if="currentAccountId">
|
|
<PendingEmailVerificationBanner v-if="hideOnOnboardingView" />
|
|
<PaymentPendingBanner v-if="hideOnOnboardingView" />
|
|
<LowBackupCodesBanner v-if="hideOnOnboardingView" />
|
|
</template>
|
|
<router-view v-slot="{ Component }">
|
|
<transition name="fade" mode="out-in">
|
|
<component :is="Component" />
|
|
</transition>
|
|
</router-view>
|
|
<WootSnackbarBox />
|
|
<NetworkNotification />
|
|
</div>
|
|
<LoadingState v-else />
|
|
</template>
|
|
|
|
<style lang="scss">
|
|
@import './assets/scss/app';
|
|
|
|
.v-popper--theme-tooltip .v-popper__inner {
|
|
background: black !important;
|
|
font-size: 0.75rem;
|
|
padding: 4px 8px !important;
|
|
border-radius: 6px;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.v-popper--theme-tooltip .v-popper__arrow-container {
|
|
display: none;
|
|
}
|
|
</style>
|