Skip to content

Commit 6b327f2

Browse files
committed
Add hasSetupData to avoid enabling 2FA again
1 parent 56bc4e3 commit 6b327f2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

resources/js/composables/useTwoFactorAuth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { qrCode, recoveryCodes, secretKey } from '@/routes/two-factor';
2-
import { ref } from 'vue';
2+
import { computed, ref } from 'vue';
33

44
const fetchJson = async <T>(url: string): Promise<T> => {
55
const response = await fetch(url, {
@@ -17,6 +17,8 @@ const qrCodeSvg = ref<string | null>(null);
1717
const manualSetupKey = ref<string | null>(null);
1818
const recoveryCodesList = ref<string[]>([]);
1919

20+
const hasSetupData = computed<boolean>(() => qrCodeSvg.value !== null && manualSetupKey.value !== null);
21+
2022
export const useTwoFactorAuth = () => {
2123
const fetchQrCode = async (): Promise<void> => {
2224
const { svg } = await fetchJson<{ svg: string; url: string }>(qrCode.url());
@@ -61,6 +63,7 @@ export const useTwoFactorAuth = () => {
6163
qrCodeSvg,
6264
manualSetupKey,
6365
recoveryCodesList,
66+
hasSetupData,
6467
clearSetupData,
6568
clearTwoFactorAuthData,
6669
fetchQrCode,

resources/js/pages/settings/TwoFactor.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const breadcrumbs: BreadcrumbItem[] = [
3030
},
3131
];
3232
33-
const { clearTwoFactorAuthData } = useTwoFactorAuth();
33+
const { hasSetupData, clearTwoFactorAuthData } = useTwoFactorAuth();
3434
const showSetupModal = ref<boolean>(false);
3535
3636
onUnmounted(() => {
@@ -54,9 +54,10 @@ onUnmounted(() => {
5454
</p>
5555

5656
<div>
57-
<Form v-bind="enable.form()" @success="showSetupModal = true" #default="{ processing }">
58-
<Button type="submit" :disabled="processing"> <ShieldCheck />Enable 2FA</Button>
59-
</Form>
57+
<Button v-if="hasSetupData" @click="showSetupModal = true"> <ShieldCheck />Continue Setup </Button>
58+
<Form v-else v-bind="enable.form()" @success="showSetupModal = true" #default="{ processing }">
59+
<Button type="submit" :disabled="processing"> <ShieldCheck />Enable 2FA</Button></Form
60+
>
6061
</div>
6162
</div>
6263

0 commit comments

Comments
 (0)