Skip to content

Commit 0a1e4ea

Browse files
refactor: package into global
1 parent 8bfceb5 commit 0a1e4ea

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/SupabaseClient.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ export default class SupabaseClient<
9999
const defaultStorageKey = `sb-${new URL(this.authUrl).hostname.split('.')[0]}-auth-token`
100100
this.storageKey = options?.auth?.storageKey ?? defaultStorageKey
101101

102-
const settings = { ...DEFAULT_OPTIONS?.global, ...options }
103-
const authSettings = Object.assign(DEFAULT_OPTIONS.global, DEFAULT_OPTIONS.auth, settings.auth)
104-
const dbSettings = Object.assign(DEFAULT_OPTIONS.global, DEFAULT_OPTIONS.db, settings.db)
102+
const settings = Object.assign(DEFAULT_OPTIONS, options)
105103

106-
this.headers = settings.headers
104+
const authSettings = settings.auth
105+
const dbSettings = settings.db
107106

108-
this.auth = this._initSupabaseAuthClient(authSettings, this.headers, this.fetch)
109-
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), this.fetch)
107+
this.headers = settings.global.headers
108+
109+
this.auth = this._initSupabaseAuthClient(authSettings, this.headers, settings.global.fetch)
110+
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch)
110111

111112
this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime })
112113
this.rest = new PostgrestClient(`${_supabaseUrl}/rest/v1`, {

src/lib/types.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ export type SupabaseClientOptions<SchemaName> = {
4949
* Options passed to the realtime-js instance
5050
*/
5151
realtime?: RealtimeClientOptions
52-
/**
53-
* A custom `fetch` implementation.
54-
*/
55-
fetch?: Fetch
56-
/**
57-
* Optional headers for initializing the client.
58-
*/
59-
headers?: Record<string, string>
52+
global?: {
53+
/**
54+
* A custom `fetch` implementation.
55+
*/
56+
fetch?: Fetch
57+
/**
58+
* Optional headers for initializing the client.
59+
*/
60+
headers?: Record<string, string>
61+
}
6062
}
6163

6264
export type SupabaseRealtimePayload<T> = {

0 commit comments

Comments
 (0)