|
74 | 74 |
|
75 | 75 | <script setup lang="ts"> |
76 | 76 |
|
77 | | - import { onMounted, nextTick, onBeforeUnmount, ref, watch } from 'vue'; |
| 77 | + import { onMounted, nextTick, onBeforeUnmount, ref, watch, onBeforeMount } from 'vue'; |
78 | 78 | import { useCoreStore } from '@/stores/core'; |
79 | 79 | import { useUserStore } from '@/stores/user'; |
80 | 80 | import { callAdminForthApi, loadFile } from '@/utils'; |
|
95 | 95 | const router = useRouter(); |
96 | 96 | const codeError = ref(null); |
97 | 97 |
|
| 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 | +
|
98 | 109 | const handleOnComplete = (value) => { |
99 | 110 | sendCode(value, 'TOTP', null); |
100 | 111 | }; |
|
121 | 132 | const isPasskeysSupported = ref(false); |
122 | 133 |
|
123 | 134 | 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); |
129 | 146 | } |
130 | | - document.addEventListener('focusin', handleGlobalFocusIn, true); |
131 | | - focusFirstAvailableOtpInput(); |
132 | | - const rootEl = otpRoot.value; |
133 | | - rootEl && rootEl.addEventListener('focusout', handleFocusOut, true); |
134 | 147 | }); |
135 | 148 |
|
136 | 149 | watch(route, (newRoute) => { |
|
0 commit comments