@@ -19,7 +19,12 @@ import {
1919 DEFAULT_REALTIME_OPTIONS ,
2020} from './lib/constants'
2121import { 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'
2328import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
2429import { Fetch , GenericSchema , SupabaseClientOptions , SupabaseAuthClientOptions } from './lib/types'
2530
@@ -96,6 +101,8 @@ export default class SupabaseClient<
96101 this . storageKey = settings . auth . storageKey ?? ''
97102 this . headers = settings . global . headers ?? { }
98103
104+ checkAuthorizationHeader ( this . headers )
105+
99106 if ( ! settings . accessToken ) {
100107 this . auth = this . _initSupabaseAuthClient (
101108 settings . auth ?? { } ,
@@ -285,10 +292,14 @@ export default class SupabaseClient<
285292 headers ?: Record < string , string > ,
286293 fetch ?: Fetch
287294 ) {
288- const authHeaders = {
289- Authorization : `Bearer ${ this . supabaseKey } ` ,
295+ const authHeaders : { [ header : string ] : string } = {
290296 apikey : `${ this . supabaseKey } ` ,
291297 }
298+
299+ if ( isJWT ( this . supabaseKey ) ) {
300+ authHeaders . Authorization = `Bearer ${ this . supabaseKey } `
301+ }
302+
292303 return new SupabaseAuthClient ( {
293304 url : this . authUrl ,
294305 headers : { ...authHeaders , ...headers } ,
0 commit comments