[Vuejs]-Nuxt 3: plugin and global middleware infinite loop?

0👍

Firstly, You have used probably plugin’s own store function useAuthStore() for getting states and may be plugin repeated issues resulting page refresh and changes. Rather use Nuxt own composable like useState()

Secondly, you have to navigate somewhere after middleware run with combination of navigateTo() method but in your code after promise what will it do was not defined.

Thirdly, provide condition to the states like: if(!authByHash) { await navigateTo('/') } or something like this and redirect.

Fourthly, try to fetch states check point at the route validation level instead of middleware, something like the followings:

<script setup>
definePageMeta({
  validate: async (route) => {
    // Check if the id is made up of digits
    return /^\d+$/.test(route.params.id)
  }
})
</script>

Leave a comment