From 9748c0c331601bf22dc8047c82db79b8e7866202 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 28 Sep 2025 04:01:31 +0000 Subject: [PATCH] Wire client to server API for posts and onboarding to avoid RLS issues cgen-4d11caba61394f70aed01c897057e1b2 --- client/lib/supabase-service.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/lib/supabase-service.ts b/client/lib/supabase-service.ts index 8e30de43..8ceec496 100644 --- a/client/lib/supabase-service.ts +++ b/client/lib/supabase-service.ts @@ -235,6 +235,14 @@ export const achievementService = { // Community Services export const communityService = { async getPosts(limit = 10): Promise { + // Prefer server API (service role) to avoid RLS issues + try { + const resp = await fetch(`/api/posts?limit=${limit}`); + if (resp.ok) { + const data = await resp.json(); + if (Array.isArray(data) && data.length) return data; + } + } catch {} try { const { data, error } = await supabase .from("community_posts") @@ -281,6 +289,14 @@ export const communityService = { "id" | "created_at" | "updated_at" | "likes_count" | "comments_count" >, ): Promise { + try { + const resp = await fetch(`/api/posts`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(post), + }); + if (resp.ok) return await resp.json(); + } catch {} try { const { data, error } = await supabase .from("community_posts") @@ -316,6 +332,10 @@ export const communityService = { }, async getUserPosts(userId: string): Promise { + try { + const resp = await fetch(`/api/user/${userId}/posts`); + if (resp.ok) return await resp.json(); + } catch {} try { const { data, error } = await supabase .from("community_posts")