opnform/client/middleware/01.check-auth.global.js

17 lines
577 B
JavaScript
Raw Normal View History

2023-12-19 17:57:31 +00:00
import {fetchAllWorkspaces} from "~/stores/workspaces.js";
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) {
const {data, error} = await useOpnApi('user')
authStore.setUser(data.value)
2023-12-19 17:57:31 +00:00
// Load workspaces
const workspaceStore = useWorkspacesStore()
const {data: workspacesData, error: workspacesError} = await fetchAllWorkspaces()
workspaceStore.save(workspacesData.value)
2023-12-16 18:21:03 +00:00
}
})