Empty response in pinia store from server API using $fetch
On a server route
server/api/offices/index.post.ts
, supabase is (successfully) used to update an "office". We are returning this office on the server route.
In the office pinia store, we use this method to add the office via the server:
However, the data
does not contain the added office and is just an empty object.
The fetching of offices with $fetch and callOnce does work as expected. We have applied the suggestions from this awesome video: https://www.youtube.com/watch?v=njsGVmcWviY
What are we doing wrong? If anyone has an example with pinia + CRUD server API, it would be awesome to share it with us 🙏Alexander Lichter
YouTube
You are using useFetch WRONG! (I hope you don't)
💪🏻 useFetch is a mighty composable to fetch data in your Nuxt.js application. It can do so many things, from updating state to refreshing calls easily and even data caching is possible. But often I see that people misuse useFetch because it is so tempting to use all the features, even when you shouldn't. In this video I show the most common mist...
5 Replies
Server code:
if you could put that in a simple reproduction (without supabase is fine) on https://nuxt.new that'd help to take a look at
Nuxt.new
Start a new Nuxt project
also, where do you log
data
? before offices.value.push(data);
?Update: the code is working as intended in edge.. but not chrome 😂 Thanks again for all your input Alex! Much appreciated! 🙇♂️
Oh, that's weird 🙈
Of course!