Can we perfomr Authentication, Database connection, etc. on server?

I’ve explored using Supabase Auth on Plamic. I tried to do that using the visual builder and not plasmic’s code component. Spoiler, I got stuck at setting the jwt cookies from supabase on the client because ‘document.cookie’ wasn’t working on plasmic, I’ve now come to know that I probably should use ‘window.document.cookie’. But I’ve not continued that journey. I decided to use Plasmic Auth to save time.

Anyways, back to your question.

What I’ve learnt from that nightmare:

This action runs on server only -

image

Option 1, you can use the Generic HTTP integration

This allows you to put in the connection URL and default headers that goes with every request. Everything added here will be on plasmic server side. Just make sure to use the anon key from supabase and not the service key.

Note, according to supabase, anon key and the URL is okay to be exposed on the client side. This is what they mentioned in their video tuts and also what their ai told me. more info on the anon key from supabase docs

image

Then you can write the API calls here. Supabase generates the API Docs automatically, you can copy and paste them appropriately here.

Option 2, If you are talking about using Supabase Js Library, unfortunately, I don’t think it’s possible to just use Plasmic Studio for that.

Option 3, you can directly use supabase integration with your Plasmic Studio project. This simplifies everything, and you can easily write custom SQL queries too. SQL here will be run on the server.

However if you go with option 3, and want to restrict user based data on your web app, you will have to use Plasmic Auth and disable RLS policies on your supabase database. link to plasmic docs explaining the process

If you do use Plasmic Auth, it is important to use the currentUser object when referring to a user. more info on the currenUser object from plasmic docs

I hope this sheds some light on what you are looking for. And I hope someone from the plasmic team can verify the plasmic-related stuff I’ve mentioned.

2 Likes