const PUBLIC_ROUTES = ['/login', '/register']

export default defineNuxtRouteMiddleware((to) => {
  const { isAuthenticated } = useAuth()
  if (!isAuthenticated.value && !PUBLIC_ROUTES.includes(to.path)) {
    return navigateTo('/login')
  }
  if (isAuthenticated.value && PUBLIC_ROUTES.includes(to.path)) {
    return navigateTo('/')
  }
})
