Skip to content

Commit 36d6c29

Browse files
committed
fix: add onBeforeMount lifecycle hook for authorization check in TwoFactorsConfirmation and TwoFactorsSetup components
1 parent de6a029 commit 36d6c29

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

custom/TwoFactorsConfirmation.vue

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
<script setup lang="ts">
7676
77-
import { onMounted, nextTick, onBeforeUnmount, ref, watch } from 'vue';
77+
import { onMounted, nextTick, onBeforeUnmount, ref, watch, onBeforeMount } from 'vue';
7878
import { useCoreStore } from '@/stores/core';
7979
import { useUserStore } from '@/stores/user';
8080
import { callAdminForthApi, loadFile } from '@/utils';
@@ -95,6 +95,17 @@
9595
const router = useRouter();
9696
const codeError = ref(null);
9797
98+
onBeforeMount(() => {
99+
if (localStorage.getItem('isAuthorized') === 'true') {
100+
coreStore.fetchMenuAndResource();
101+
if (route.query.next) {
102+
router.push(route.query.next.toString());
103+
} else {
104+
router.push({ name: 'home' });
105+
}
106+
}
107+
})
108+
98109
const handleOnComplete = (value) => {
99110
sendCode(value, 'TOTP', null);
100111
};
@@ -121,16 +132,18 @@
121132
const isPasskeysSupported = ref(false);
122133
123134
onMounted(async () => {
124-
await nextTick();
125-
await isCMAAvailable();
126-
tagOtpInputs();
127-
if (isPasskeysSupported.value === true) {
128-
checkIfUserHasPasskeys();
135+
if (localStorage.getItem('isAuthorized') !== 'true') {
136+
await nextTick();
137+
await isCMAAvailable();
138+
tagOtpInputs();
139+
if (isPasskeysSupported.value === true) {
140+
checkIfUserHasPasskeys();
141+
}
142+
document.addEventListener('focusin', handleGlobalFocusIn, true);
143+
focusFirstAvailableOtpInput();
144+
const rootEl = otpRoot.value;
145+
rootEl && rootEl.addEventListener('focusout', handleFocusOut, true);
129146
}
130-
document.addEventListener('focusin', handleGlobalFocusIn, true);
131-
focusFirstAvailableOtpInput();
132-
const rootEl = otpRoot.value;
133-
rootEl && rootEl.addEventListener('focusout', handleFocusOut, true);
134147
});
135148
136149
watch(route, (newRoute) => {

custom/TwoFactorsSetup.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
<script setup lang="ts">
6969
70-
import { onMounted, onBeforeUnmount, nextTick, ref, watchEffect,computed,watch } from 'vue';
70+
import { onMounted, onBeforeUnmount, nextTick, ref, watchEffect,computed,watch, onBeforeMount } from 'vue';
7171
import { useCoreStore } from '@/stores/core';
7272
import { useUserStore } from '@/stores/user';
7373
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
@@ -86,6 +86,16 @@ import ErrorMessage from '@/components/ErrorMessage.vue';
8686
const { t } = useI18n();
8787
const route = useRoute()
8888
89+
onBeforeMount(() => {
90+
if (localStorage.getItem('isAuthorized') === 'true') {
91+
coreStore.fetchMenuAndResource();
92+
if (route.query.next) {
93+
router.push(route.query.next.toString());
94+
} else {
95+
router.push({ name: 'home' });
96+
}
97+
}
98+
})
8999
90100
const code = ref(null);
91101
const codeError = ref(null);

0 commit comments

Comments
 (0)