I’m building an app in Plasmic with a Supabase backend and my plan is to totally avoid using the supabase integration that Plasmic provides since it basically gets rid of most of the benefits of Supabase, especially RLS.
Instead, I’ll be using code components to run data fetching & mutation to/from Supabase (via data fetching code components)
This means I can use the normal supabase-js library and interact with supabase via the auto-generated API rather than direct connection.
I’m still working out the details of how to efficiently implement this (most notably, how I can authenticate users)
However, I’ve had partial success so far: I have written a data providing component for one of my supabase tables inspired by the data fetching code component example on the page linked above.
My example provider is attached
I then register that component in plasmic-init.ts
using the code below.
Then in Plasmic Studio I can add the StaffProvider component to a page. This exposes a state variable called Staff with data fetched from supabase.
After adding the StaffProvider component to a page, I also get element actions available within that page that I can use to create, edit and delete staff. These can hooked up to forms or buttons in Plasmic to update data in supabase.
So far, my solution is working using the plasmic loader, and I haven’t needed to start using codegen.
If anyone wants to collaborate on getting this approach working, please let me know.
PLASMIC.registerComponent(StaffProvider, {
name: 'StaffProvider',
providesData: true,
props: {
children: 'slot'
},
refActions: {
deleteStaff: {
description: 'delete a staff member',
argTypes: [
{name: 'Staff ID', type: 'number'}
]
},
addStaff: {
description: 'add a staff member',
argTypes: [
{name: 'staff', type: 'object'}
]
},
editStaff: {
description: 'edit a staff member',
argTypes: [
{name: 'staff', type: 'object'}
]
}
}
})
StaffProvider.tsx