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

Hello,

I am trying to connect to a back-end which is Supabase. I read a few post and article on how to connect to Supabase. And I am making good progress!

But I want to know how to write code or actions that will run on server only.

There are many actions or code that I feel needs to run only on the server and not on client. Like for example connection URL that contain secret key, executing queries, etc.

For example I want to write code or action that will execute multiple SQL queries and return output that I will display to user in front-end web app.

How can I define that code or actions that need to run on server?

Sorry to ask such a stupid question but as I come from Frappe Framework background where all authentication and database related activities are generally performed on server and not at client level.

TIA

1 Like

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.

1 Like