Skip to content

Commit

Permalink
fix: custom authorization header should not be overwritten (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Oct 10, 2022
1 parent 0e298d5 commit 2f271f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/SupabaseClient.ts
Expand Up @@ -248,7 +248,7 @@ export default class SupabaseClient<
}
return new SupabaseAuthClient({
url: this.authUrl,
headers: { ...headers, ...authHeaders },
headers: { ...authHeaders, ...headers },
storageKey: storageKey,
autoRefreshToken,
persistSession,
Expand Down
12 changes: 11 additions & 1 deletion test/SupabaseAuthClient.test.ts
@@ -1,5 +1,5 @@
import { SupabaseAuthClient } from '../src/lib/SupabaseAuthClient'
import { SupabaseClientOptions } from '../src/lib/types'
import SupabaseClient from '../src/SupabaseClient'
import { DEFAULT_HEADERS } from '../src/lib/constants'

const DEFAULT_OPTIONS = {
Expand All @@ -23,3 +23,13 @@ test('it should create a new instance of the class', () => {
const authClient = new SupabaseAuthClient(authSettings)
expect(authClient).toBeInstanceOf(SupabaseAuthClient)
})

test('_initSupabaseAuthClient should overwrite authHeaders if headers are provided', () => {
const authClient = new SupabaseClient('https://example.supabase.com', 'supabaseKey')[
'_initSupabaseAuthClient'
](authSettings, {
Authorization: 'Bearer custom-auth-header',
})
expect(authClient['headers']['Authorization']).toBe('Bearer custom-auth-header')
expect(authClient['headers']['apikey']).toBe('supabaseKey')
})

0 comments on commit 2f271f8

Please sign in to comment.