export default defineNuxtRouteMiddleware(async (to, _from) => {

  const { fetchUser, setUser } = useDirectusAuth()
  const { refreshTokens } = useDirectusToken()
  
  const user = useDirectusUser()
  
  if (!user.value) {
    const user = await fetchUser()
    setUser(user.value)
    refreshTokens()
  }

  if (!user.value) {
    return navigateTo("/login")
  }

})