@@ -14,21 +14,24 @@ import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
14
14
import { SupabaseRealtimeChannel } from './lib/SupabaseRealtimeChannel'
15
15
import { Fetch , GenericSchema , SupabaseClientOptions , SupabaseAuthClientOptions } from './lib/types'
16
16
17
- const DEFAULT_OPTIONS = {
18
- auth : {
19
- autoRefreshToken : true ,
20
- persistSession : true ,
21
- detectSessionInUrl : true ,
22
- } ,
23
- global : {
24
- headers : DEFAULT_HEADERS ,
25
- } ,
17
+ const DEFAULT_GLOBAL_OPTIONS = {
18
+ headers : DEFAULT_HEADERS ,
19
+ }
20
+
21
+ const DEFAULT_DB_OPTIONS = {
26
22
db : {
27
23
schema : 'public' ,
28
- shouldThrowOnError : false ,
29
24
} ,
30
25
}
31
26
27
+ const DEFAULT_AUTH_OPTIONS : SupabaseAuthClientOptions = {
28
+ autoRefreshToken : true ,
29
+ persistSession : true ,
30
+ detectSessionInUrl : true ,
31
+ }
32
+
33
+ const DEFAULT_REALTIME_OPTIONS : RealtimeClientOptions = { }
34
+
32
35
/**
33
36
* Supabase Client.
34
37
*
@@ -99,22 +102,43 @@ export default class SupabaseClient<
99
102
const defaultStorageKey = `sb-${ new URL ( this . authUrl ) . hostname . split ( '.' ) [ 0 ] } -auth-token`
100
103
this . storageKey = options ?. auth ?. storageKey ?? defaultStorageKey
101
104
102
- const settings = Object . assign ( DEFAULT_OPTIONS , options )
103
-
104
- const authSettings = settings . auth
105
- const dbSettings = settings . db
105
+ const {
106
+ db : dbOptions ,
107
+ auth : authOptions ,
108
+ realtime : realtimeOptions ,
109
+ global : globalOptions ,
110
+ } = options || { }
111
+
112
+ const settings = {
113
+ db : {
114
+ ...DEFAULT_DB_OPTIONS ,
115
+ ...dbOptions ,
116
+ } ,
117
+ auth : {
118
+ ...DEFAULT_AUTH_OPTIONS ,
119
+ storageKey : defaultStorageKey ,
120
+ ...authOptions ,
121
+ } ,
122
+ realtime : {
123
+ ...DEFAULT_REALTIME_OPTIONS ,
124
+ ...realtimeOptions ,
125
+ } ,
126
+ global : {
127
+ ...DEFAULT_GLOBAL_OPTIONS ,
128
+ ...globalOptions ,
129
+ } ,
130
+ }
106
131
107
- this . headers = settings . global . headers
132
+ this . headers = { ... DEFAULT_HEADERS , ... globalOptions ?. headers }
108
133
109
- this . auth = this . _initSupabaseAuthClient ( authSettings , this . headers , settings . global . fetch )
134
+ this . auth = this . _initSupabaseAuthClient ( settings . auth , this . headers , settings . global . fetch )
110
135
this . fetch = fetchWithAuth ( supabaseKey , this . _getAccessToken . bind ( this ) , settings . global . fetch )
111
136
112
137
this . realtime = this . _initRealtimeClient ( { headers : this . headers , ...settings . realtime } )
113
138
this . rest = new PostgrestClient ( `${ _supabaseUrl } /rest/v1` , {
114
139
headers : this . headers ,
115
- schema : dbSettings . schema ,
140
+ schema : settings ?. db ? .schema ,
116
141
fetch : this . fetch ,
117
- throwOnError : dbSettings . shouldThrowOnError ,
118
142
} )
119
143
120
144
this . _listenForAuthEvents ( )
0 commit comments