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

10 lines
313 B
JavaScript
Raw Normal View History

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)
}
})