From b55d386b35cdf9373fabbbc07199f86811bde339 Mon Sep 17 00:00:00 2001 From: Wen Bo Xie <5532241+w3b6x9@users.noreply.github.com> Date: Tue, 31 Jan 2023 22:38:49 -0800 Subject: [PATCH] feat: pass global header bearer token as apikey to RealtimeClient (#699) --- src/SupabaseClient.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index eba42aac..153f406f 100644 --- a/src/SupabaseClient.ts +++ b/src/SupabaseClient.ts @@ -265,9 +265,11 @@ export default class SupabaseClient< } private _initRealtimeClient(options: RealtimeClientOptions) { + const authHeader = options.headers?.Authorization + const authToken = authHeader?.startsWith('Bearer ') && authHeader.split(' ')[1] return new RealtimeClient(this.realtimeUrl, { ...options, - params: { ...{ apikey: this.supabaseKey }, ...options?.params }, + params: { ...{ apikey: authToken || this.supabaseKey }, ...options?.params }, }) }