Replies: 1 comment 5 replies
-
|
You should not use Calling databases from the server is safer, even if it's Supabase, even if you have strong RLS policies. You should really use remote functions, run the Supabase insertion on the server side and handle optimistic updates on the client, so it's not necessary to refresh the page. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I am building a SvelteKit application with Supabase, hosted on Vercel. My app involves standard CRUD operations, and I have implemented strong Row Level Security (RLS) policies on my database.
I am deciding between two architectural patterns for handling data writes (specifically INSERT) and want to understand the consensus on best practices regarding Vercel function usage and cost.
The Scenario
I have a simple form to add data. I see two ways to handle this:
Approach 1: SvelteKit Form Actions (Server-Side)
The request hits a Vercel Serverless Function, which then communicates with Supabase.
Approach 2: Direct Client-Side SDK
Since my RLS is secure, I bypass the Vercel server and write directly to Supabase from the component.
My Questions
Is Approach 2 (Client-Side) considered a valid "best practice" in the SvelteKit ecosystem specifically to optimize for serverless costs, or is bypassing Form Actions discouraged for other reasons?
Does using invalidateAll() in the client-side approach carry any significant performance penalties compared to the automatic revalidation that happens with Form Actions?
Are there edge cases (outside of progressive enhancement) where the Client-Side SDK approach fails in production?
Thanks for the help!
Beta Was this translation helpful? Give feedback.
All reactions