@@ -19,7 +19,12 @@ import {
19
19
DEFAULT_REALTIME_OPTIONS ,
20
20
} from './lib/constants'
21
21
import { fetchWithAuth } from './lib/fetch'
22
- import { stripTrailingSlash , applySettingDefaults } from './lib/helpers'
22
+ import {
23
+ stripTrailingSlash ,
24
+ applySettingDefaults ,
25
+ isJWT ,
26
+ checkAuthorizationHeader ,
27
+ } from './lib/helpers'
23
28
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
24
29
import { Fetch , GenericSchema , SupabaseClientOptions , SupabaseAuthClientOptions } from './lib/types'
25
30
@@ -96,6 +101,8 @@ export default class SupabaseClient<
96
101
this . storageKey = settings . auth . storageKey ?? ''
97
102
this . headers = settings . global . headers ?? { }
98
103
104
+ checkAuthorizationHeader ( this . headers )
105
+
99
106
if ( ! settings . accessToken ) {
100
107
this . auth = this . _initSupabaseAuthClient (
101
108
settings . auth ?? { } ,
@@ -285,10 +292,14 @@ export default class SupabaseClient<
285
292
headers ?: Record < string , string > ,
286
293
fetch ?: Fetch
287
294
) {
288
- const authHeaders = {
289
- Authorization : `Bearer ${ this . supabaseKey } ` ,
295
+ const authHeaders : { [ header : string ] : string } = {
290
296
apikey : `${ this . supabaseKey } ` ,
291
297
}
298
+
299
+ if ( isJWT ( this . supabaseKey ) ) {
300
+ authHeaders . Authorization = `Bearer ${ this . supabaseKey } `
301
+ }
302
+
292
303
return new SupabaseAuthClient ( {
293
304
url : this . authUrl ,
294
305
headers : { ...authHeaders , ...headers } ,
0 commit comments