export default defineNuxtRouteMiddleware(async (to) => {
    const auth = useAuthStore()

    // Don't block routes for unauthenticated users — auth middleware handles them first.
    if (!auth.isAuthenticated) {
        return
    }

    const { loaded, loadSidebar, isRouteDisabled } = useSidebar()

    if (!loaded.value) {
        await loadSidebar()
    }

    if (isRouteDisabled(to.path)) {
        return navigateTo('/')
    }
})
