d3ro-voice/packages/api-client/src/supabase-browser.ts
2026-08-29 18:33:45 +09:00

28 lines
1,002 B
TypeScript

// packages/api-client/src/supabase-browser.ts
// 브라우저 컴포넌트용 Supabase 클라이언트 (캐싱 싱글턴).
// Database 제네릭 주입 (@supabase/ssr 0.10 + supabase-js 2.103 정합).
import { createBrowserClient } from '@supabase/ssr'
import type { Database } from './types'
import { requireSupabasePublicConfig } from './client'
let cachedClient: ReturnType<typeof createBrowserClient<Database>> | null = null
export function getSupabaseBrowserClient(): ReturnType<typeof createBrowserClient<Database>> {
if (cachedClient) return cachedClient
const { url, anonKey } = requireSupabasePublicConfig({
url: process.env.NEXT_PUBLIC_SUPABASE_URL,
anonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
})
cachedClient = createBrowserClient<Database>(url, anonKey)
return cachedClient
}
export function isSupabaseConfigured(): boolean {
return Boolean(
process.env.NEXT_PUBLIC_SUPABASE_URL?.trim()
&& process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY?.trim(),
)
}