ROIpad ← Back to Search
stackoverflow › answer

Answer to: A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function

Score: 2 • Accepted
Answered: Aug 17, 2025
User Rep: 144
I was able to solve this by wrapping the logic within an import.meta.client if statement. Composables are available only on the client side, hence it couldn't resolve it on SSR. This worked for me. export default defineNuxtRouteMiddleware(async () => { // Do this only on the client side if (import.meta.client) { const newSession = await useNewSession() const accessToken = newSession.access_token const { data, error } = await useFetch('/api/organization', { headers: { 'Authorization': `Bearer ${accessToken}` }, }) if (error.value) { throw error } const organizationCookie = useCookie('af-organization') organizationCookie.value = JSON.stringify(data.value) } })
vue.js nuxt.js nuxt-middleware
View Question ↗