I'm having some issues with the function hooks. I'...
# help
b
I'm having some issues with the function hooks. I'm trying to create a stripe account after a new row is added to the profile. Using postman I can create a stripe account with the api.. But when I change it to use the function hook, I get the following error: Database+error+saving+new+user. Anyone run into this issue before?
g
You are going to need to provide more info on your function hook. Is it a trigger off an insert to a table (auth.users maybe)? The error probably means your function failed when it was called adding a user. This is usually an RLS issue if you tested the function directly and it worked, but then call it from the API especially if there is no user yet.
b
I turned off the RLS, so I can try to find where the issue is coming from. The condition fires off from an Insert to a custom Profiles table. I've also added into the Http params for the function.
Is there a chance that the error is coming from my API function?
Copy code
await supabase
    .from("profiles")
    .update({
      stripe_customer: customer.id,
    })
    .eq("id", req.body.record.id);
g
Are you writing your own trigger function and using http() extension or using the Supabase Function Hooks in the UI?
b
I'm using Supabase function hooks, which is sending a post request to an API following Insert to Profiles.
g
Your error sort of implied something was happening off of the addition of a new user. Not sure how that error message comes from a update to your own table...
b
I have a function and a trigger to create a profile for each new user and that works fine without the function hook. The only thing the hook does is send a post request, so I'm not sure why I'm getting a database error off that. That's why I assumed ti has something to do with the API it's posting to.
g
OK so that explains the error on new user. Since it works without the extra function hook on the table and you have RLS off for now it is likely then it is an error in the hook. One thing that will happen is if you don't get an API response back in some short number of seconds, auth will timeout waiting for the db to insert to the table. I do not know if hooks return an error if your API errors, I've not actually used them but have used http() function and know a too slow response from the external API server will error creating the user.
Does the function hook work if you just insert to the profile table directly? IE auth is not involved.
As an aside, I would personally not put any external calls on creating a new user directly. If your external API (stripe, postman, etc) is offline, delayed or errors you lose your user sign up. I'd either do that with a separate server function or in extra calls from your client api after you have captured the user. Then use RLS to only allow paid users, or fully processed users to have access to what you want.
b
Ah okay, that makes sense. In this video I'm watching, that's how he stripe acc was set up. But the recommendation is to separate it from the sign up as well. I'll do that, it's a work around but it might save headaches in the future.
m
afternoon -- anyone have any success using Function Hooks to send JSON payload over to Slack via HTTP POST?
haven't been able to debug the calls from within supabase, and slack is not reporting success / failure of incoming webhooks