From 9ae26f974ed2ae7dfe096f3b20dda4eec8440473 Mon Sep 17 00:00:00 2001 From: Wen Bo Xie Date: Tue, 31 Jan 2023 22:19:58 -0800 Subject: [PATCH] feat: pass global header bearer token as apikey to RealtimeClient --- 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 }, }) }