Supabase. How make rpc call to call a database function?

Hello everyone,

I have a dropdown menu that lists the workspaces that the logged-in user is a part of, and I would like to set an onchange action that makes an RPC call to my set_active_workspace(workspace_id) function in Weweb.

The Supabase documentation is not comprehensive on how to set all the necessary permissions to connect to the database, call the function, and link the call to the logged-in user.

Can anyone help me with this?

Thanks in advance for your collaboration

Alessandro

1 Like

Hello, this is the setup I’m using. Let me know if anything is not clear.
Fields are your function parameters.
Authorization, is user session token

Hopefully @Alexis will bless us with a functionality to call functions natively, also for Edge Functions, in the upcoming WeWeb’s Supabase Plugin update.

You can also call functions via the exposed Supabase instance, for more versatility, but I don’t think you’d want to do that, as it’s some code actually.

3 Likes

It works just as I hoped. Thank you very much! :pray:

2 Likes

Hi, what do you have in result.key?
I tried with a function of mine but it’s returning empty value. There’s no RLS enabled
On Supabase, the logs says 200, which is successful

Thanks in Advance

Hi, what if I want to make an rpc call for database function as anonymous user? How to do it?

Thanks.

Hello, it’s the same process, you just need to set your RLS up, if you’re calculating that into your function as well, to allow the anon users to make changes or whatever you’re doing with the function. Or you can use the security INVOKER way, but it’s discouraged to use the security INVOKER.

1 Like

Thank you very much @Broberto! :pray: I managed to setup a proper REST API call to my function according to your guidance.

Amazing :slight_smile: