File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ export default class SupabaseClient {
96
96
this . auth = this . _initSupabaseAuthClient ( settings )
97
97
this . realtime = this . _initRealtimeClient ( { headers : this . headers , ...settings . realtime } )
98
98
99
- this . fetch = fetchWithAuth ( this . _getAccessToken . bind ( this ) , settings . fetch )
99
+ this . fetch = fetchWithAuth ( supabaseKey , this . _getAccessToken . bind ( this ) , settings . fetch )
100
100
101
101
this . _listenForAuthEvents ( )
102
102
this . _listenForMultiTabEvents ( )
Original file line number Diff line number Diff line change @@ -23,17 +23,22 @@ export const resolveHeadersConstructor = () => {
23
23
}
24
24
25
25
export const fetchWithAuth = (
26
+ supabaseKey : string ,
26
27
getAccessToken : ( ) => Promise < string | null > ,
27
28
customFetch ?: Fetch
28
29
) : Fetch => {
29
30
const fetch = resolveFetch ( customFetch )
30
31
const HeadersConstructor = resolveHeadersConstructor ( )
31
32
32
33
return async ( input , init ) => {
33
- const accessToken = await getAccessToken ( )
34
+ const accessToken = ( await getAccessToken ( ) ) ?? supabaseKey
34
35
let headers = new HeadersConstructor ( init ?. headers )
35
36
36
- if ( ! headers . has ( 'Authorization' ) && accessToken ) {
37
+ if ( ! headers . has ( 'apikey' ) ) {
38
+ headers . set ( 'apikey' , supabaseKey )
39
+ }
40
+
41
+ if ( ! headers . has ( 'Authorization' ) ) {
37
42
headers . set ( 'Authorization' , `Bearer ${ accessToken } ` )
38
43
}
39
44
You can’t perform that action at this time.
0 commit comments