// apps/mobile/lib/supabase.ts // React Native용 Supabase 클라이언트 — AsyncStorage 어댑터 + URL polyfill import 'react-native-url-polyfill/auto' import AsyncStorage from '@react-native-async-storage/async-storage' import { createClient, type SupabaseClient } from '@supabase/supabase-js' import Constants from 'expo-constants' const supabaseUrl = (Constants.expoConfig?.extra?.supabaseUrl as string | undefined) ?? '' const supabaseAnonKey = (Constants.expoConfig?.extra?.supabaseAnonKey as string | undefined) ?? '' export function isSupabaseConfigured(): boolean { return Boolean(supabaseUrl && supabaseAnonKey) } function createSupabaseClient(): SupabaseClient { if (!isSupabaseConfigured()) { // env 미설정 시에도 크래시 방지용 더미 클라이언트 생성 // 런타임에서 isSupabaseConfigured()로 체크 후 사용 return createClient('https://localhost.invalid', 'no-key', { auth: { storage: AsyncStorage, persistSession: false, detectSessionInUrl: false } }) } return createClient(supabaseUrl, supabaseAnonKey, { auth: { storage: AsyncStorage, autoRefreshToken: true, persistSession: true, detectSessionInUrl: false } }) } export const supabase = createSupabaseClient()