| import { createClient as createSupabaseClient } from '@supabase/supabase-js' |
| import type { Database } from 'types/database' |
| import { isSupabaseConfigured as isSupabaseConfiguredEnv, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, SUPABASE_URL } from './env' |
|
|
| export const isSupabaseConfigured = isSupabaseConfiguredEnv |
|
|
| import type { SupabaseClient } from '@supabase/supabase-js' |
|
|
| export const createServerClient = async (opts?: { service?: boolean }): Promise<SupabaseClient<Database>> => { |
| |
| |
| if (opts?.service && SUPABASE_URL && SUPABASE_SERVICE_ROLE_KEY) { |
| return createSupabaseClient<Database>(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, { |
| auth: { persistSession: false } |
| }) |
| } |
|
|
| |
| |
| |
| if (!SUPABASE_URL || !SUPABASE_ANON_KEY) { |
| |
| |
| |
| |
| const missingClient = new Proxy({}, {
|
| get() {
|
| return () => {
|
| throw new Error('Supabase not configured: missing NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY')
|
| }
|
| }
|
| }) as SupabaseClient<Database>
|
|
|
| return missingClient
|
| }
|
|
|
| return createSupabaseClient<Database>(SUPABASE_URL, SUPABASE_ANON_KEY, { |
| auth: { persistSession: false } |
| }) |
| } |
|
|
| |
| export const createServiceClient = () => { |
| if (!SUPABASE_URL || !SUPABASE_SERVICE_ROLE_KEY) { |
| throw new Error('Service role key not configured')
|
| }
|
|
|
| const noopAsyncStorage = {
|
| async getItem(_key: string) {
|
| return null
|
| },
|
| async setItem(_key: string, _value: any) {
|
| return
|
| },
|
| async removeItem(_key: string) {
|
| return
|
| }
|
| }
|
|
|
| return createSupabaseClient<Database>(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, {
|
| auth: {
|
| persistSession: false,
|
|
|
| storage: noopAsyncStorage
|
| }
|
| })
|
| } |
|
|