|
1 | | -import { createRouter, createWebHistory } from "vue-router" |
| 1 | +import { createSpaRouter } from "@/shared/createSpaRouter" |
2 | 2 | import { effortRoutes as routes } from "./routes" |
3 | 3 | import { useRequireLogin } from "@/composables/RequireLogin" |
4 | 4 | import { checkHasOnePermission } from "@/composables/CheckPagePermission" |
5 | 5 | import { useFetch } from "@/composables/ViperFetch" |
6 | 6 | import { useUserStore } from "@/store/UserStore" |
7 | | -import { useRouteFocus } from "@/composables/use-route-focus" |
8 | 7 |
|
9 | | -const baseUrl = import.meta.env.VITE_VIPER_HOME |
10 | | -const router = createRouter({ |
11 | | - scrollBehavior: () => ({ left: 0, top: 0 }), |
12 | | - history: createWebHistory(baseUrl), |
13 | | - routes, |
14 | | -}) |
| 8 | +const router = createSpaRouter(routes) |
15 | 9 |
|
16 | 10 | // Dedup latch: reuse in-flight fetch so concurrent navigations don't fire multiple requests |
17 | 11 | let evalPermissionsPromise: Promise<void> | null = null |
18 | 12 |
|
19 | 13 | async function loadEvalPermissions() { |
20 | | - const userStore = useUserStore() |
21 | | - const existingPermissions = userStore.userInfo?.permissions ?? [] |
22 | | - const { get } = useFetch() |
23 | | - const apiUrl = import.meta.env.VITE_API_URL |
24 | | - const evalPerms = await get(`${apiUrl}loggedInUser/permissions?prefix=SVMSecure.Eval`) |
25 | | - if (evalPerms.success && Array.isArray(evalPerms.result)) { |
26 | | - userStore.setPermissions([...existingPermissions, ...evalPerms.result]) |
27 | | - } else { |
28 | | - // Reset latch so the next navigation retries the fetch |
| 14 | + try { |
| 15 | + const userStore = useUserStore() |
| 16 | + const existingPermissions = userStore.userInfo?.permissions ?? [] |
| 17 | + const { get } = useFetch() |
| 18 | + const apiUrl = import.meta.env.VITE_API_URL |
| 19 | + const evalPerms = await get(`${apiUrl}loggedInUser/permissions?prefix=SVMSecure.Eval`) |
| 20 | + if (evalPerms.success && Array.isArray(evalPerms.result)) { |
| 21 | + userStore.setPermissions([...existingPermissions, ...evalPerms.result]) |
| 22 | + } |
| 23 | + } finally { |
| 24 | + // Reset latch so future session changes refetch instead of reusing the old resolved promise |
29 | 25 | evalPermissionsPromise = null |
30 | 26 | } |
31 | 27 | } |
@@ -63,6 +59,4 @@ router.beforeEach(async (to, from) => { |
63 | 59 | } |
64 | 60 | }) |
65 | 61 |
|
66 | | -useRouteFocus(router) |
67 | | - |
68 | 62 | export { router as effortRouter } |
0 commit comments