| import { createClient } from '@supabase/supabase-js' |
|
|
| const supabaseUrl = import.meta.env.VITE_SUPABASE_URL |
| const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY |
|
|
| const hasCredentials = supabaseUrl && supabaseAnonKey && |
| supabaseUrl !== 'undefined' && supabaseAnonKey !== 'undefined'; |
|
|
| |
| const createChainablePromise = (resolvedValue) => { |
| const promise = Promise.resolve(resolvedValue); |
| const chain = { |
| select: () => chain, |
| order: () => chain, |
| eq: () => chain, |
| then: (onFulfilled, onRejected) => promise.then(onFulfilled, onRejected), |
| catch: (onRejected) => promise.catch(onRejected) |
| }; |
| return chain; |
| }; |
|
|
| |
| const mockSupabase = { |
| from: () => ({ |
| select: () => createChainablePromise({ data: [], error: null }), |
| insert: () => createChainablePromise({ data: null, error: new Error("Supabase credentials not configured in environment.") }), |
| update: () => ({ eq: () => createChainablePromise({ error: new Error("Supabase credentials not configured.") }) }), |
| delete: () => ({ eq: () => createChainablePromise({ error: new Error("Supabase credentials not configured.") }) }) |
| }), |
| storage: { |
| from: () => ({ |
| upload: () => createChainablePromise({ data: null, error: new Error("Supabase credentials not configured.") }), |
| remove: () => createChainablePromise({ error: new Error("Supabase credentials not configured.") }), |
| getPublicUrl: () => ({ data: { publicUrl: "" } }) |
| }) |
| } |
| }; |
|
|
| export const supabase = hasCredentials |
| ? createClient(supabaseUrl, supabaseAnonKey) |
| : mockSupabase; |
|
|
|
|