## 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>
166 lines
3.2 KiB
Vue
166 lines
3.2 KiB
Vue
<!-- DEPRECIATED -->
|
|
<!-- TODO: Replace this banner component with NextBanner "app/javascript/dashboard/components-next/banner/Banner.vue" -->
|
|
<script>
|
|
import NextButton from 'dashboard/components-next/button/Button.vue';
|
|
|
|
export default {
|
|
components: {
|
|
NextButton,
|
|
},
|
|
props: {
|
|
bannerMessage: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
hrefLink: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
hrefLinkText: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
hasActionButton: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
actionButtonVariant: {
|
|
type: String,
|
|
default: 'faded',
|
|
},
|
|
actionButtonLabel: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
actionButtonIcon: {
|
|
type: String,
|
|
default: 'i-lucide-arrow-right',
|
|
},
|
|
colorScheme: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
hasCloseButton: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
},
|
|
emits: ['primaryAction', 'close'],
|
|
computed: {
|
|
bannerClasses() {
|
|
const classList = [this.colorScheme];
|
|
|
|
if (this.hasActionButton || this.hasCloseButton) {
|
|
classList.push('has-button');
|
|
}
|
|
return classList;
|
|
},
|
|
// TODO - Remove this method when we standardize
|
|
// the button color and variant names
|
|
getButtonColor() {
|
|
const colorMap = {
|
|
primary: 'blue',
|
|
secondary: 'blue',
|
|
alert: 'ruby',
|
|
warning: 'amber',
|
|
};
|
|
|
|
return colorMap[this.colorScheme] || 'blue';
|
|
},
|
|
},
|
|
methods: {
|
|
onClick(e) {
|
|
this.$emit('primaryAction', e);
|
|
},
|
|
onClickClose(e) {
|
|
this.$emit('close', e);
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="flex items-center justify-center h-12 gap-4 px-4 py-3 text-xs text-white banner dark:text-white woot-banner"
|
|
:class="bannerClasses"
|
|
>
|
|
<span class="banner-message">
|
|
{{ bannerMessage }}
|
|
<a
|
|
v-if="hrefLink"
|
|
:href="hrefLink"
|
|
rel="noopener noreferrer nofollow"
|
|
target="_blank"
|
|
>
|
|
{{ hrefLinkText }}
|
|
</a>
|
|
</span>
|
|
<div class="actions">
|
|
<NextButton
|
|
v-if="hasActionButton"
|
|
xs
|
|
:icon="actionButtonIcon"
|
|
:variant="actionButtonVariant"
|
|
:color="getButtonColor"
|
|
:label="actionButtonLabel"
|
|
@click="onClick"
|
|
/>
|
|
<NextButton
|
|
v-if="hasCloseButton"
|
|
xs
|
|
variant="ghost"
|
|
icon="i-lucide-circle-x"
|
|
:color="getButtonColor"
|
|
:label="$t('GENERAL_SETTINGS.DISMISS')"
|
|
@click="onClickClose"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.banner {
|
|
&.primary {
|
|
@apply bg-n-brand;
|
|
}
|
|
|
|
&.secondary {
|
|
@apply bg-n-slate-3 dark:bg-n-solid-3 text-n-slate-12;
|
|
a {
|
|
@apply text-n-slate-12;
|
|
}
|
|
}
|
|
|
|
&.alert {
|
|
@apply bg-n-ruby-3 text-n-ruby-12;
|
|
|
|
a {
|
|
@apply text-n-ruby-12;
|
|
}
|
|
}
|
|
|
|
&.warning {
|
|
@apply bg-n-amber-5 text-n-amber-12;
|
|
a {
|
|
@apply text-n-amber-12;
|
|
}
|
|
}
|
|
|
|
&.gray {
|
|
@apply text-n-gray-10 dark:text-n-gray-10;
|
|
}
|
|
|
|
a {
|
|
@apply ml-1 underline text-n-amber-12 text-xs;
|
|
}
|
|
|
|
.banner-message {
|
|
@apply flex items-center;
|
|
}
|
|
|
|
.actions {
|
|
@apply flex gap-1 right-3;
|
|
}
|
|
}
|
|
</style>
|