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")