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

12 lines
373 B
JavaScript

import {useWorkspacesStore} from "~/stores/workspaces.js";
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)
}
})