From 6c819a31569e2717570a358dcfa4847304d27cb3 Mon Sep 17 00:00:00 2001 From: coder-soft Date: Mon, 20 Apr 2026 15:31:33 +0500 Subject: [PATCH 1/2] feat(creator-packs): add RLS policy and integrate Supabase client --- opencode.json | 10 ++++++++++ src/components/Hero.tsx | 13 +++++++------ src/hooks/useCreatorPacks.ts | 16 ++++++++++++++-- src/integrations/supabase/client.ts | 2 +- .../20260420000000_creator_packs_rls_policy.sql | 14 ++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 opencode.json create mode 100644 supabase/migrations/20260420000000_creator_packs_rls_policy.sql diff --git a/opencode.json b/opencode.json new file mode 100644 index 0000000..32e975a --- /dev/null +++ b/opencode.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://opencode.ai/config.json", + "mcp": { + "supabase": { + "type": "remote", + "url": "https://mcp.supabase.com/mcp?project_ref=bmywdrwjdqmrkafhiuwn&features=docs%2Cdatabase%2Cdebugging%2Cdevelopment%2Cfunctions%2Cbranching", + "enabled": true + } + } +} \ No newline at end of file diff --git a/src/components/Hero.tsx b/src/components/Hero.tsx index d5f9c0e..f7e5d80 100644 --- a/src/components/Hero.tsx +++ b/src/components/Hero.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react" import { Link } from "react-router-dom" -import { IconArrowRight, IconExternalLink, IconFolderOpen, IconMusic } from "@tabler/icons-react" +import { IconArrowRight, IconExternalLink, IconFolderOpen, IconMusic, IconPackage } from "@tabler/icons-react" import { useIsMobile } from "@/hooks/use-mobile" import * as motion from "motion/react-client" @@ -143,13 +143,14 @@ const Hero = () => { - - - Open Music Packs + + + Creator Packs - - Browse All Resources + + + Music Packs diff --git a/src/hooks/useCreatorPacks.ts b/src/hooks/useCreatorPacks.ts index 4ec2caf..cb42317 100644 --- a/src/hooks/useCreatorPacks.ts +++ b/src/hooks/useCreatorPacks.ts @@ -116,10 +116,22 @@ export const useCreatorPacks = () => { .eq('status', 'approved') .order('created_at', { ascending: false }); - if (error) throw error; + if (error) { + console.error('Supabase error details:', { + message: error.message, + details: error.details, + hint: error.hint, + code: error.code + }); + throw error; + } + console.log('Fetched packs:', data); setPacks((data as CreatorPackWithProfiles[])?.map(mapToCreatorPack) || []); } catch (error: unknown) { - console.error('Error fetching creator packs:', getErrorMessage(error)); + console.error('Error fetching creator packs:', error); + if (error && typeof error === 'object' && 'message' in error) { + console.error('Error details:', (error as { message: unknown }).message); + } } finally { setIsLoading(false); } diff --git a/src/integrations/supabase/client.ts b/src/integrations/supabase/client.ts index e8996c8..d709120 100644 --- a/src/integrations/supabase/client.ts +++ b/src/integrations/supabase/client.ts @@ -3,7 +3,7 @@ import { createClient } from '@supabase/supabase-js'; import type { Database } from './types'; const SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL as string; -const SUPABASE_PUBLISHABLE_KEY = import.meta.env.VITE_SUPABASE_ANON_KEY as string; +const SUPABASE_PUBLISHABLE_KEY = import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY as string; // Import the supabase client like this: // import { supabase } from "@/integrations/supabase/client"; diff --git a/supabase/migrations/20260420000000_creator_packs_rls_policy.sql b/supabase/migrations/20260420000000_creator_packs_rls_policy.sql new file mode 100644 index 0000000..65a97da --- /dev/null +++ b/supabase/migrations/20260420000000_creator_packs_rls_policy.sql @@ -0,0 +1,14 @@ +-- Drop existing policies if they exist to avoid conflicts +DROP POLICY IF EXISTS "Creator packs are publicly readable if approved" ON creator_packs; +DROP POLICY IF EXISTS "Users can manage their own creator packs" ON creator_packs; + +-- Allow anyone to read approved creator packs +CREATE POLICY "Creator packs are publicly readable if approved" ON creator_packs +FOR SELECT +USING (status = 'approved'); + +-- Allow users to insert, update, and delete their own creator packs +CREATE POLICY "Users can manage their own creator packs" ON creator_packs +FOR ALL +USING (auth.uid() = user_id) +WITH CHECK (auth.uid() = user_id); \ No newline at end of file From b4a921100ad2e1cdd31e62346f4e1c9875da4100 Mon Sep 17 00:00:00 2001 From: coder-soft Date: Mon, 20 Apr 2026 20:24:25 +0500 Subject: [PATCH 2/2] fix: remove debug log, add admin RLS policy, gitignore opencode.json --- .gitignore | 3 ++- src/hooks/useCreatorPacks.ts | 1 - .../20260420000000_creator_packs_rls_policy.sql | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 86db642..0f5a99c 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ api_docs.md telemetry-id public/qrafty.otf public/JetBrainsMono-Regular.ttf -export-resources.yml \ No newline at end of file +export-resources.yml +opencode.json \ No newline at end of file diff --git a/src/hooks/useCreatorPacks.ts b/src/hooks/useCreatorPacks.ts index cb42317..697fb0c 100644 --- a/src/hooks/useCreatorPacks.ts +++ b/src/hooks/useCreatorPacks.ts @@ -125,7 +125,6 @@ export const useCreatorPacks = () => { }); throw error; } - console.log('Fetched packs:', data); setPacks((data as CreatorPackWithProfiles[])?.map(mapToCreatorPack) || []); } catch (error: unknown) { console.error('Error fetching creator packs:', error); diff --git a/supabase/migrations/20260420000000_creator_packs_rls_policy.sql b/supabase/migrations/20260420000000_creator_packs_rls_policy.sql index 65a97da..7bcf15c 100644 --- a/supabase/migrations/20260420000000_creator_packs_rls_policy.sql +++ b/supabase/migrations/20260420000000_creator_packs_rls_policy.sql @@ -11,4 +11,10 @@ USING (status = 'approved'); CREATE POLICY "Users can manage their own creator packs" ON creator_packs FOR ALL USING (auth.uid() = user_id) -WITH CHECK (auth.uid() = user_id); \ No newline at end of file +WITH CHECK (auth.uid() = user_id); + +-- Allow admins to review creator packs +CREATE POLICY "Admins can review creator packs" ON creator_packs +FOR UPDATE +USING (auth.jwt() ->> 'email' = 'yamura@duck.com') +WITH CHECK (auth.jwt() ->> 'email' = 'yamura@duck.com'); \ No newline at end of file