N
Nuxt4mo ago
QRST

Quick Question - Supabase Client Fetch vs API route fetch

Hey guys, Using supabase, which is better? 1) Directly fetch data in a component or store. 2) Fetching from a server route. Just looking for quick response on why one of the other would be used.
No description
1 Reply
brunomgmateus
brunomgmateus4mo ago
It should be the same result AFAIK, but to me using server api brings a better workflow, as it becomes easier and cleaner to handle as the project increases in size. Not only fetching logic becomes separated, but the data fetching is actually done on the server side, instead of possibly exposing the fetched resource server on the client and possibly CORS errors (but it can also be mitigated with 'server: true' when fetching directly). Defining allowed methods is also a breeze, as is the whole api structuring. Also, if you would like to access that data from other apps, or php, etc, you would just point it to the endpoint. However, pay attention to securing your api, as I've seen the wild endpoints that delete stuff from database without any protection. Just something to be aware of.
Want results from more Discord servers?
Add your server