Using custom $fetch outside Nuxt Context (Pinia Store) produces error but still works
Hello!
Quick background, I followed this guide: https://notes.atinux.com/nuxt-custom-fetch on how to create a custom $fetch implementation, and for now it works on some parts of my app calling it inside some Pinia functions, but now I stumbled upon an error when using it like this:
This is a function inside a useAuthStore(), which is called by an initStore plugin which only does that.
And it calls the
fetchWorkspaces()
function which is:
But the problem that I'm getting is an error in the console/terminal which is: [nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug
and also in browser console:
I've been doing a little research on this but I can't understand why calling the fetchWorkspaces method gives this error, while the fetchUser method doesn't, even though I get the data back, if I do a console.log of the response of fetchWorkspaces, the data is there. Thanks in advance1 Reply
Did you try passing the $pinia object? https://pinia.vuejs.org/ssr/nuxt.html#Awaiting-for-actions-in-pages
Pinia 🍍
Intuitive, type safe, light and flexible Store for Vue