🎯 Update a Record in Supabase
565
Once you've added Supabase Collection of data to WeWeb, you might want to allow users to manipulate the data in that Collection.
In this article, we'll cover how to:
- add an update Workflow in WeWeb, and
- restrict update permissions to authenticated users in Supabase.
Setup an update Workflow in WeWeb
In the example below, we are using the "Update row" Workflow that comes by default with the Data Grid Element:
The trigger is "On Row update".
Since we added the Supabase Data Source Plugin, we have access to all the CRUD actions available in Supabase.
In this case, we chose the "Update" action, selected the "vehicles" table and mapped the "id" to the id of the Workflow Event:
Then, we tell WeWeb we want to update the "mileage" field in our Supabase table, and send the value in the "mileage" column of our Data Grid:
And that's it!
If you switch to Preview mode, you will be update your Supabase table from your WeWeb Data Grid:
🔥 Pro Tip 🔥
By default, the fields in the Data Grid Element are Text fields but you can change the input type to Number if you need to send numerical data to your database:
Restrict who can modify a record in Supabase
By default, all the data in the tables that are in the "public" schema of your Supabase project can be read, updated, or deleted.
Supabase allows you to enable Row-Level Security for each of your tables:
If you want to restrict certain actions to specific users or roles, you'll need to:
Supabase provides a number of policy templates to get you started:
In the example below, we tell Supabase that users can:
- update a record
- in the "locations" table of the "public" schema
- if they are authenticated
🔥 Pro Tip 🔥
Once you enable RLS on a Supabase table, you won't be able to access the data in a WeWeb Collection unless you've added a policy.