Replies: 1 comment
|
Direct client-side writes are completely valid when you use the anon key and have solid RLS policies. I would use a server action only when the operation needs a secret, service-role access, trusted server validation, or several coordinated writes. invalidateAll() can reload more data than necessary, so for a simple insert I would update the local state optimistically or invalidate only the affected route/data. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!
All reactions