Skip to content

Commit 24865c5

Browse files
committed
Add credentials to custom fetch implementation
1 parent b288b6c commit 24865c5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/core/supabase-js/src/SupabaseClient.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default class SupabaseClient<
151151
})
152152
}
153153

154-
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch)
154+
this.fetch = this._createFetchWithAuth(settings.global.fetch)
155155
this.realtime = this._initRealtimeClient({
156156
headers: this.headers,
157157
accessToken: this._getAccessToken.bind(this),
@@ -206,6 +206,10 @@ export default class SupabaseClient<
206206
relation: string,
207207
options?: PostgrestQueryBuilderOptions
208208
): PostgrestQueryBuilder<ClientOptions, Schema, any> {
209+
if (options?.fetch) {
210+
options.fetch = this._createFetchWithAuth(options.fetch)
211+
}
212+
209213
return this.rest.from(relation, options)
210214
}
211215

@@ -408,4 +412,8 @@ export default class SupabaseClient<
408412
this.changedAccessToken = undefined
409413
}
410414
}
415+
416+
private _createFetchWithAuth(_fetch?: typeof global.fetch) {
417+
return fetchWithAuth(this.supabaseKey, this._getAccessToken.bind(this), _fetch)
418+
}
411419
}

0 commit comments

Comments
 (0)