import type { RouteLocationNormalized } from '#vue-router'

export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) => {
  // https://github.com/WaldemarEnns/nuxtui-github-auth/blob/7e3110f933d5d0445d3ac89d6c84c48052b49041/middleware/auth.global.ts
  const { loggedIn } = useUserSession()

  if (to.meta.auth === false) {
    return
  }

  if (!loggedIn.value) {
    return navigateTo('/login')
  }
})
