Need Help with Nuxt Middleware: Unexpected Behavior with navigateTo() Function

Hey everyone, I tried to implement an authentication flow to my Nuxt app, but I got stuck at the authentication middleware. When I use "return navigateTo('/')", the code after the middleware still runs. Is it normal for the navigateTo function to behave this way in a middleware?
<script setup>
definePageMeta({
middleware: [
function (to, from) {
console.log('middleware start')
return navigateTo('/')
},
],
})

console.log('this code should not running') // ...but running :(
</script>
<script setup>
definePageMeta({
middleware: [
function (to, from) {
console.log('middleware start')
return navigateTo('/')
},
],
})

console.log('this code should not running') // ...but running :(
</script>
If I use "return '/'" instead, it works as expected, but I'm not sure if this is a reliable solution:
<script setup>
definePageMeta({
middleware: [
function (to, from) {
console.log('middleware start')
return '/'
},
],
})

console.log('this code should not running') // Not running as expected
</script>
<script setup>
definePageMeta({
middleware: [
function (to, from) {
console.log('middleware start')
return '/'
},
],
})

console.log('this code should not running') // Not running as expected
</script>
5 Replies
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
SzaDave πŸ‘½
SzaDave πŸ‘½β€’2y ago
I'm on 3.4.1.
Cue
Cueβ€’2y ago
Just to confirm, this is executing on server side, not client side Seems intermittent too
SzaDave πŸ‘½
SzaDave πŸ‘½β€’2y ago
Yes, its executing on the server side.
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server