11// Connects Supabase to Expo React Native
22import 'react-native-url-polyfill/auto'
3- import { createClient } from '@supabase/supabase-js'
3+ import { createClient , SupabaseClient } from '@supabase/supabase-js'
44import 'expo-sqlite/localStorage/install' ;
5+ import Constants from "expo-constants" ;
6+ import AsyncStorage from '@react-native-async-storage/async-storage' ;
57
8+ const extras = Constants . expoConfig ?. extra ?? { } ;
69const supabaseUrl = process . env . EXPO_PUBLIC_SUPABASE_URL
710const supabaseAnonKey = process . env . EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY
11+ // allow supabase to be null if env vars are missing
12+ export let supabase : SupabaseClient | null = null ;
813
9- if ( ! supabaseUrl || ! supabaseAnonKey ) {
10- throw new Error ( "Missing Supabase environment variables." )
11- }
12-
13- export const supabase = createClient ( supabaseUrl , supabaseAnonKey , {
14- auth : {
15- storage : localStorage ,
16- autoRefreshToken : true ,
17- persistSession : true ,
18- detectSessionInUrl : false ,
19- } ,
20- } )
14+ if ( supabaseUrl && supabaseAnonKey ) {
15+ supabase = createClient ( supabaseUrl , supabaseAnonKey , {
16+ auth : {
17+ storage : AsyncStorage ,
18+ autoRefreshToken : true ,
19+ persistSession : true ,
20+ detectSessionInUrl : false ,
21+ } ,
22+ } ) ;
23+ } else {
24+ // do not throw, allow app to run without Supabase for dev or missing config
25+ console . warn ( '[supabase] env vars missing. running without Supabase' ) ;
26+ }
0 commit comments