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
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)
}
})
View Question ↗
Question
Parent Entity
Score: 2 • Views: 298
Site: stackoverflow
SaaS Metrics