@@ -20,8 +20,13 @@ const DEFAULT_OPTIONS = {
20
20
persistSession : true ,
21
21
detectSessionInUrl : true ,
22
22
} ,
23
- general : {
23
+ global : {
24
+ timeoutMs : 500 ,
25
+ headers : DEFAULT_HEADERS ,
26
+ } ,
27
+ db : {
24
28
schema : 'public' ,
29
+ shouldThrowOnError : false ,
25
30
} ,
26
31
}
27
32
@@ -95,23 +100,21 @@ export default class SupabaseClient<
95
100
const defaultStorageKey = `sb-${ new URL ( this . authUrl ) . hostname . split ( '.' ) [ 0 ] } -auth-token`
96
101
this . storageKey = options ?. auth ?. storageKey ?? defaultStorageKey
97
102
98
- const settings = { ...DEFAULT_OPTIONS ?. general , ...options }
103
+ const settings = { ...DEFAULT_OPTIONS ?. global , ...options }
104
+ const authSettings = Object . assign ( DEFAULT_OPTIONS . global , DEFAULT_OPTIONS . auth , settings . auth )
105
+ const dbSettings = Object . assign ( DEFAULT_OPTIONS . global , DEFAULT_OPTIONS . db , settings . db )
99
106
100
- this . headers = { ...DEFAULT_HEADERS , ...options ?. headers }
107
+ this . headers = { ...DEFAULT_OPTIONS ?. global ?. headers , ...options ?. headers }
101
108
102
- this . auth = this . _initSupabaseAuthClient (
103
- settings . auth || DEFAULT_OPTIONS . auth ,
104
- this . headers ,
105
- settings . fetch
106
- )
107
- this . fetch = fetchWithAuth ( supabaseKey , this . _getAccessToken . bind ( this ) , settings . fetch )
109
+ this . auth = this . _initSupabaseAuthClient ( authSettings , this . headers , this . fetch )
110
+ this . fetch = fetchWithAuth ( supabaseKey , this . _getAccessToken . bind ( this ) , this . fetch )
108
111
109
112
this . realtime = this . _initRealtimeClient ( { headers : this . headers , ...settings . realtime } )
110
113
this . rest = new PostgrestClient ( `${ _supabaseUrl } /rest/v1` , {
111
114
headers : this . headers ,
112
- schema : options ?. db ? .schema ,
115
+ schema : dbSettings . schema ,
113
116
fetch : this . fetch ,
114
- throwOnError : options ?. db ?. shouldThrowOnError || false ,
117
+ throwOnError : dbSettings . shouldThrowOnError ,
115
118
} )
116
119
117
120
this . _listenForAuthEvents ( )
0 commit comments