Skip to content

Commit 14bc550

Browse files
committed
Add credentials to custom fetch implementation
1 parent 14825b2 commit 14bc550

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/SupabaseClient.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class SupabaseClient<
145145
})
146146
}
147147

148-
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch)
148+
this.fetch = this._createFetchWithAuth(settings.global.fetch)
149149
this.realtime = this._initRealtimeClient({
150150
headers: this.headers,
151151
accessToken: this._getAccessToken.bind(this),
@@ -200,6 +200,10 @@ export default class SupabaseClient<
200200
relation: string,
201201
options?: PostgrestQueryBuilderOptions
202202
): PostgrestQueryBuilder<ClientOptions, Schema, any> {
203+
if (options?.fetch) {
204+
options.fetch = this._createFetchWithAuth(options.fetch)
205+
}
206+
203207
return this.rest.from(relation, options)
204208
}
205209

@@ -386,4 +390,8 @@ export default class SupabaseClient<
386390
this.changedAccessToken = undefined
387391
}
388392
}
393+
394+
private _createFetchWithAuth(_fetch?: typeof global.fetch) {
395+
return fetchWithAuth(this.supabaseKey, this._getAccessToken.bind(this), _fetch)
396+
}
389397
}

0 commit comments

Comments
 (0)