export default defineNuxtRouteMiddleware(async (to) => {
  if (to.path.startsWith('/auth/')) {
    return
  }

  const { isAuthenticated, login, fetch } = useAuth()

  // Only fetch session if not already authenticated
  if (!isAuthenticated.value) {
    await fetch()
  }

  if (!isAuthenticated.value) {
    await login()
  }
})
