export default defineNuxtRouteMiddleware(async (to, from) => {
  // Only run on client-side
  if (process.server) return

  const authStore = useAuthStore()

  // Check if route requires authentication
  const requiresAuth = to.meta.middleware === 'auth'

  if (requiresAuth) {
    // Check auth status if not already checked
    if (!authStore.isLoggedIn) {
      await authStore.checkAuth()
    }

    // Redirect to login if not authenticated
    if (!authStore.isLoggedIn) {
      return navigateTo('/login')
    }
  }
})

