Spaces:
Running
Running
| import { createClient } from '@supabase/supabase-js'; | |
| const url = import.meta.env.VITE_SUPABASE_URL; | |
| const anon = import.meta.env.VITE_SUPABASE_ANON_KEY; | |
| if (!url || !anon) { | |
| // Helpful logs if something’s still off | |
| console.error('Env seen by app:', { | |
| VITE_SUPABASE_URL: url, | |
| VITE_SUPABASE_ANON_KEY: anon ? '(set)' : '(missing)' | |
| }) | |
| throw new Error('Missing VITE_SUPABASE_URL or VITE_SUPABASE_ANON_KEY'); | |
| } | |
| export const supabase = createClient(url, anon); | |
| // Helper to run GraphQL queries for features not available in REST | |
| export async function graphql(query, variables) { | |
| const apiKey = service || anon | |
| const res = await fetch(`${supabaseUrl}/graphql/v1`, { | |
| method: 'POST', | |
| headers: { | |
| 'content-type': 'application/json', | |
| 'apikey': apiKey, | |
| 'authorization': `Bearer ${apiKey}` | |
| }, | |
| body: JSON.stringify({ query, variables }) | |
| }) | |
| const json = await res.json() | |
| if (json.errors) { | |
| console.error('GraphQL errors:', json.errors) | |
| } | |
| return json.data | |
| } | |