Nuxt 3 Middleware issue

middleware/auth.js
export default defineNuxtRouteMiddleware((to,from)=>{
    const cookie = useCookie('__session')
    if(!cookie.value){
        console.log("cookie.value is none")
        return navigateTo('/admin/login')
    }
    console.log('Cookie found:', cookie.value)
})


Dashboard.vue
<template>
<h1>Dashboard</h1>

</template>

<script setup>
definePageMeta({
    middleware: ['auth'],
})
</script>



  • Navigate to is getting fired regardless if cookie value exist or not
  • When cookie value exists it doesn't do console.log("cookie.value is none") still navigate to works
  • I tried opening the dashboard from different url, it lands to /admin/login
Was this page helpful?