Am I dumb? I have been really trying to insert int...
# help
e
Am I dumb? I have been really trying to insert into my supabase, but it's just not working. Method looks like:
Copy code
javascript
  const insertListing = async () => {
    try {
      const { data, error } = await client
        .from("product")
        .insert([{ title: "hello" }], { returning: "minimal" });
      console.log(data || error);
    } catch (error) {
      alert(error.message);
    }
  };
I see that I am an authenticated user in the session when I run the function And I can see that I am hitting the API: 200 OPTIONS /rest/vi/product But I get an error in my console: FetchError: Failed to fetch Not sure what it's trying to fetch if minimal is on... and this is an insert any way. Should this be an OPTIONS rather than POST?
n
Hello @Efizzz! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
g
OPTIONS is the CORS preflight request. You should see another network request having POST with it. Unless your OPTIONS request failed CORS for some reason. The "fetch" error is probably referring to the fetch function used for any of the http network requests.
n
Efizzz (2022-04-14)
t
Can I suggest removing data variable from the const and the console.log I can’t find the evidence in supabase or postgrest docs to back up my theory though I think it might be worth a shot!
e
@garyaustin Ya, I am not seeing any POST after it
My Network panel does show a cancelled fetch
@tourdownunder I tried removing the data variable as well, no change besides I don't get the log anymore
FetchError: Failed to fetch comes back in data it seems
g
I use that all the time... What is your environment? And is there any response in the OPTIONS
e
local environment, really just started integrating supabase as a POC
OPTIONS response from supabase console:
Copy code
{
  "headers": [
    {
      "cf_cache_status": "DYNAMIC",
      "cf_ray": "6fbfb54bc67318ee-EWR",
      "content_length": "0",
      "content_location": null,
      "content_range": null,
      "content_type": null,
      "date": "Thu, 14 Apr 2022 21:59:22 GMT",
      "transfer_encoding": null,
      "x_kong_proxy_latency": null,
      "x_kong_upstream_latency": null
    }
  ],
  "origin_time": 72,
  "status_code": 200
}
No response being saved in network panel
g
By environment I meant framework? Is your supabase instance local also or to the cloud one? What is the URL on the OPTIONS request?
e
Connecting to cloud, "https://acfxojkwxfktrxymychv.supabase.co/rest/v1/product?columns=%22title%22"
Was that your GET? 401 error
g
This is a good OPTIONS Response header
Does a select request work? Seems something fundamental wrong versus Insert and Post.
e
Got rejected again
Failed to fetch
Supabase is rejecting me? 😢
g
Can you show the code on client setup (mask your key at least partially) and you never did answer what framework, is this just javascript?
e
Oh I see, this is using react. create react app
Initializing the client, I provide it via a Context
.env variables
Function call, I grab the client from the context and call insert via button push
Can confirm client is connected, this is from breakpoint if I look at client
I see fetch is undefined?
Current session has user logged in and authenticated as well
g
fetch part is fine, just means you are not overriding it.
Been awhile since I used react. Can you console.log client right before your insert or select.
e
Yeah that's what this is
But I can do again, copy and paste the whole bit
g
Any chance some of this is running on SSR type stuff? Your user login worked evidently so when that ran you successfully ran a fetch...
e
Hmmmm it is a basic create-react-app, so would have SSR disabled by default
But good point
Auth did work
g
like I said, I have not used react in awhile, just know SSR changes how things need to flow.
e
Oh totally fine, np, I really appreciate the help
Could it be an issue with the database instance itself?
I had done a create-react-app with supabase probably a half year ago and was able to insert to DB
Separate instance
g
lots of people use it so nothing wrong with react/supabase.
The response on OPTIONS is just strange. Maybe you could compare a signin POST (would be token?grant_type=password) and see if things look different in headers and URL....