Skip to content

Commit 2f271f8

Browse files
authored
fix: custom authorization header should not be overwritten (#584)
1 parent 0e298d5 commit 2f271f8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/SupabaseClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export default class SupabaseClient<
248248
}
249249
return new SupabaseAuthClient({
250250
url: this.authUrl,
251-
headers: { ...headers, ...authHeaders },
251+
headers: { ...authHeaders, ...headers },
252252
storageKey: storageKey,
253253
autoRefreshToken,
254254
persistSession,

test/SupabaseAuthClient.test.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SupabaseAuthClient } from '../src/lib/SupabaseAuthClient'
2-
import { SupabaseClientOptions } from '../src/lib/types'
2+
import SupabaseClient from '../src/SupabaseClient'
33
import { DEFAULT_HEADERS } from '../src/lib/constants'
44

55
const DEFAULT_OPTIONS = {
@@ -23,3 +23,13 @@ test('it should create a new instance of the class', () => {
2323
const authClient = new SupabaseAuthClient(authSettings)
2424
expect(authClient).toBeInstanceOf(SupabaseAuthClient)
2525
})
26+
27+
test('_initSupabaseAuthClient should overwrite authHeaders if headers are provided', () => {
28+
const authClient = new SupabaseClient('https://example.supabase.com', 'supabaseKey')[
29+
'_initSupabaseAuthClient'
30+
](authSettings, {
31+
Authorization: 'Bearer custom-auth-header',
32+
})
33+
expect(authClient['headers']['Authorization']).toBe('Bearer custom-auth-header')
34+
expect(authClient['headers']['apikey']).toBe('supabaseKey')
35+
})

0 commit comments

Comments
 (0)