Best practices re: Supabase queries from client components vs api routes
Unanswered
Valentine ant posted this in #help-forum
Valentine antOP
Hi all,
When sending queries and mutations to Supabase, is it okay to directly query against Supabase from the client component? For example, I have forms in client components that might update or insert to Supabase on submission. What would be the most "proper" approach? Would (3) be considered wrong?
1. Create an
2. Create a route handler (
3. Communicate with Supabase directly from the client component
When sending queries and mutations to Supabase, is it okay to directly query against Supabase from the client component? For example, I have forms in client components that might update or insert to Supabase on submission. What would be the most "proper" approach? Would (3) be considered wrong?
1. Create an
onSubmit handler in a server component that persists to Supabase and pass it to the client component2. Create a route handler (
POST/PUT /api/users) and call the api from the client using fetch3. Communicate with Supabase directly from the client component
4 Replies
is it okay to directly query against Supabase from the client component?No, this implies that you expose the supabase key to the client.
and people who are smart enough can get the key and use the key against you
What would be the most "proper" approach?
1. you can't pass function from server component to client component. Try it. it wont work
2. You can do this, better yet, use Server Action since it already is more secure than route handler (you still need to auth guard)
3. no, as mentioned above
Jersey Wooly
If server actions are the way to go, does that mean a /api route is mostly just used for exposing an api to third parties?