2023-12-19 17:57:31 +00:00
|
|
|
import {fetchAllWorkspaces} from "~/stores/workspaces.js";
|
2024-01-25 04:12:45 +00:00
|
|
|
import {opnFetch} from "~/composables/useOpnApi.js";
|
2023-12-19 12:46:55 +00:00
|
|
|
|
2023-12-16 18:21:03 +00:00
|
|
|
export default defineNuxtRouteMiddleware(async(to, from) => {
|
|
|
|
const authStore = useAuthStore()
|
|
|
|
authStore.initStore(useCookie('token').value, useCookie('admin_token').value)
|
|
|
|
|
|
|
|
if (authStore.token && !authStore.user) {
|
2023-12-19 17:57:31 +00:00
|
|
|
const workspaceStore = useWorkspacesStore()
|
2024-01-25 04:12:45 +00:00
|
|
|
|
|
|
|
// Load user data and workspaces
|
|
|
|
const [userDataResponse, workspacesResponse] = await Promise.all([useOpnApi('user'), fetchAllWorkspaces()]);
|
|
|
|
authStore.setUser(userDataResponse.data.value)
|
|
|
|
workspaceStore.save(workspacesResponse.data.value)
|
2023-12-16 18:21:03 +00:00
|
|
|
}
|
|
|
|
})
|