Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(2fa): display secret modal (#5092)

boojack45c6f631fe6a
diff --git a/frontend/src/components/TwoFactorSecretModal.vue b/frontend/src/components/TwoFactorSecretModal.vue
new file mode 100644
index 0000000000..d1caecb607
--- /dev/null
+++ b/frontend/src/components/TwoFactorSecretModal.vue
@@ -0,0 +1,54 @@
+<template>
+ <BBModal
+ :title="$t('two-factor.your-two-factor-secret.self')"
+ :subtitle="$t('two-factor.your-two-factor-secret.description')"
+ class="outline outline-gray-200"
+ @close="dismissModal"
+ >
+ <div class="w-auto mb-4 py-2">
+ <code class="pr-4">{{ props.secret }}</code>
+ </div>
+ <div class="w-full flex items-center justify-end space-x-3 pr-1 pb-1">
+ <button type="button" class="btn-cancel" @click="dismissModal">
+ {{ $t("common.close") }}
+ </button>
+ <button class="btn-primary" @click="copySecret">
+ {{ $t("common.copy") }}
+ </button>
+ </div>
+ </BBModal>
+</template>
+
+<script lang="ts" setup>
+import { pushNotification } from "@/store";
+import { toClipboard } from "@soerenmartius/vue3-clipboard";
+import { useI18n } from "vue-i18n";
+
+const props = defineProps({
+ secret: {
+ type: String,
+ default: "",
+ },
+});
+
+const emit = defineEmits<{
+ (event: "close"): void;
+}>();
+
+const { t } = useI18n();
+
+const dismissModal = () => {
+ emit("close");
+};
+
+const copySecret = () => {
+ toClipboard(props.secret).then(() => {
+ pushNotification({
+ module: "bytebase",
+ style: "INFO",
+ title: t("two-factor.your-two-factor-secret.copy-succeed"),
+ });
+ });
+ dismissModal();
+};
+</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index c59b5b2914..00a56749d9 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2006,6 +2006,11 @@
"self": "Disable Two-factor authentication",
"description": "You are about to disable two-factor authentication for your account. You will no longer be required to enter the security code generated by your Authenticator App when signing in."
},
+ "your-two-factor-secret": {
+ "self": "Your two-factor secret",
+ "description": "Copy the code and enter it in your TOTP app manually.",
+ "copy-succeed": "Secret copied to clipboard. Paste it into your app."
+ },
"messages": {
"2fa-enabled": "Two-factor authentication is enabled.",
"2fa-disabled": "Two-factor authentication is disabled.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index af53bca54e..61f658bfc8 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2005,6 +2005,11 @@
"self": "禁用双重认证",
"description": "您即将禁用您账户的双重认证。您在登录时将不再需要输入由您的 Authenticator 应用程序生成的安全代码。"
},
+ "your-two-factor-secret": {
+ "self": "双重认证密钥",
+ "description": "复制密钥并在您的应用程序中手动输入。",
+ "copy-succeed": "复制成功。请输入到您的应用程序中。"
+ },
"messages": {
"2fa-enabled": "双重认证开启成功",
"2fa-disabled": "双重认证禁用成功",
diff --git a/frontend/src/views/TwoFactorSetup.vue b/frontend/src/views/TwoFactorSetup.vue
index 7d4177ae7a..b20f383dd8 100644
--- a/frontend/src/views/TwoFactorSetup.vue
+++ b/frontend/src/views/TwoFactorSetup.vue
@@ -31,19 +31,16 @@
>
<template #action>
<span
- :class="!state.showSecretText && 'cursor-pointer text-blue-600'"
- @click="state.showSecretText = true"
+ :class="
+ !state.showSecretModal && 'cursor-pointer text-blue-600'
+ "
+ @click="state.showSecretModal = true"
>{{
$t(
"two-factor.setup-steps.setup-auth-app.scan-qr-code.enter-the-text"
)
}}</span
>
- <code
- v-if="state.showSecretText"
- class="ml-1 bg-gray-100 px-1 rounded font-mono"
- >{{ currentUser.mfaSecret }}</code
- >
</template>
</i18n-t>
</p>
@@ -72,6 +69,12 @@
/>
</template>
</BBStepTab>
+
+ <TwoFactorSecretModal
+ v-if="state.showSecretModal"
+ :secret="currentUser.mfaSecret"
+ @close="state.showSecretModal = false"
+ />
</template>
<script lang="ts" setup>
@@ -83,6 +86,7 @@ import * as QRCode from "qrcode";
import { UpdateUserRequest } from "@/types/proto/v1/auth_service";
import RecoveryCodesView from "@/components/RecoveryCodesView.vue";
import { useRouter } from "vue-router";
+import TwoFactorSecretModal from "@/components/TwoFactorSecretModal.vue";
const issuerName = "Bytebase";
@@ -93,7 +97,7 @@ type Step = typeof SETUP_AUTH_APP_STEP | typeof DOWNLOAD_RECOVERY_CODES_STEP;
interface LocalState {
currentStep: Step;
- showSecretText: boolean;
+ showSecretModal: boolean;
qrcodeDataUrl: string;
otpCode: string;
recoveryCodesDownloaded: boolean;
@@ -105,7 +109,7 @@ const authStore = useAuthStore();
const userStore = useUserStore();
const state = reactive<LocalState>({
currentStep: SETUP_AUTH_APP_STEP,
- showSecretText: false,
+ showSecretModal: false,
qrcodeDataUrl: "",
otpCode: "",
recoveryCodesDownloaded: false,