Hi everyone! I'm new to development so I appreciat...
# javascript
k
Hi everyone! I'm new to development so I appreciate all the help 🙂 I've started learning with Svelte.js and have grown to love it while using supabase as a backend for my simple blog site. I'm using just the fetch functions to get data from my sb db. The issue I was running into was building my blog post page. When requesting the information it would be returned as an array. Upon doing some research I found that it could be possible to get a single object back by changing the "Accept" header to "application/vnd.pgrst.object+json". It appeared to fix it but then I started getting a 401 which appears to be a CORS issue. Some guidance on this would be great since I've been stuck on this for 3+ days. Thanks!! 😄
g
Can you provide a bit more detail on your call, your actual network request with error response and any RLS you deal with. Too many variable in your description to start guessing.
Can you provide a bit more information on your calls (fetches) RLS use, and any network request/return with payload/error you are seeing. Too many variables.
First if any of those contain a service key delete now and redact. Not saying they do, but just saying.
k
Totally get it, sorry I'm new at this. This is what I'm playing with. The first is an image of my fetch request, second is the svelte error I get, the last is the response shown on my console.
g
So was this working and then it broke? You need need a bearer token (anon,service,user) in addition to apikey. I actually don't even see the apikey in your 3rd pic, but just skimming...
Copy code
curl 'https://ugccqefilvseqbseypbq.supabase.co/rest/v1/test?select=id' \
-H "apikey: SUPABASE_KEY" \
-H "Authorization: Bearer SUPABASE_KEY"
I'm not sure what you had working before, and how changing to deal with array return is impacting it. 401 is you don't have privilege to access.
k
So I got it working but the response continues to be an array 😛
g
Well obviously easy to deal with that in your handler.... but the accept header Accept: application/vnd.pgrst.object+json if added with everything else that is working is supposed to return without the array... BUT only if the select with filter returns a single row. Anything more and you get 406 error.