NuxtN
Nuxt3y ago
Cesar

Global middleware infinite redirection

Hi,


I can't get my middleware to work to block access to pages if the user is not logged in.
I have an infinite loop that I can't explain.

This is my global middleware code:


import { useAuthStore } from "~/stores/auth"

export default defineNuxtRouteMiddleware(() => {
const authStore = useAuthStore()

if (!Object.keys({...authStore.user}).length) {
console.log('not authenticated')
return navigateTo('/login')
}
})
Was this page helpful?