import { useAuthStore } from '~/stores/auth'

export default defineNuxtRouteMiddleware(async (to, from) => {
  if (process.server) return

  const authStore = useAuthStore()

  if (!authStore.initialized) {
    await authStore.initializeAuth().catch(() => {})
  }

  // If user is logged in, redirect to home
  if (authStore.isLoggedIn) {
    return navigateTo('/')
  }
})
