export default defineNuxtRouteMiddleware(async (to, from) => {
  if (import.meta.server) return

  const { token } = useAuthStore()
  if (!token) return

  const { query, name } = to
  if (name === 'note-create' && !query.id) {
    try {
      const res = await request('/website/tourism/publishTravelNotes/getDraftId')
      const id = res.data
      return navigateTo({
        path: '/note-create',
        query: {
          id
        },
        replace: true
      })
    } catch (error) {
      return
    }
  }
  return
})
