export default defineNuxtRouteMiddleware(async (to) => {
  // Skip auth routes handled by @logto/nuxt
  if (to.path === '/sign-in' || to.path === '/sign-out' || to.path === '/callback') {
    return
  }

  // Skip public auth paths
  if (to.path.startsWith('/auth/')) {
    return
  }

  const { loggedIn } = useAuth()

  if (!loggedIn.value) {
    return navigateTo('/sign-in')
  }
})
