From 325c2c9b253a81cf1f02ec7e2bdbced7318467f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20Caba=C3=A7o?= Date: Mon, 9 Dec 2024 12:45:44 +0000 Subject: [PATCH] fix: Bind proper object to setAuth on Realtime callback (#1324) --- package-lock.json | 8 ++++---- package.json | 2 +- src/SupabaseClient.ts | 13 ++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 25f17abf..35227e46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@supabase/functions-js": "2.4.3", "@supabase/node-fetch": "2.6.15", "@supabase/postgrest-js": "1.16.3", - "@supabase/realtime-js": "2.10.9", + "@supabase/realtime-js": "2.11.2", "@supabase/storage-js": "2.7.1" }, "devDependencies": { @@ -1204,9 +1204,9 @@ } }, "node_modules/@supabase/realtime-js": { - "version": "2.10.9", - "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.10.9.tgz", - "integrity": "sha512-0AjN65VDNIScZzrrPaVvlND4vbgVS+j9Wcy3zf7e+l9JY4IwCTahFenPLcKy9bkr7KY0wfB7MkipZPKxMaDnjw==", + "version": "2.11.2", + "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.11.2.tgz", + "integrity": "sha512-u/XeuL2Y0QEhXSoIPZZwR6wMXgB+RQbJzG9VErA3VghVt7uRfSVsjeqd7m5GhX3JR6dM/WRmLbVR8URpDWG4+w==", "dependencies": { "@supabase/node-fetch": "^2.6.14", "@types/phoenix": "^1.5.4", diff --git a/package.json b/package.json index 5bd61770..7bb430fd 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@supabase/functions-js": "2.4.3", "@supabase/node-fetch": "2.6.15", "@supabase/postgrest-js": "1.16.3", - "@supabase/realtime-js": "2.10.9", + "@supabase/realtime-js": "2.11.2", "@supabase/storage-js": "2.7.1" }, "devDependencies": { diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index 9f0a32c7..5058edf5 100644 --- a/src/SupabaseClient.ts +++ b/src/SupabaseClient.ts @@ -117,8 +117,11 @@ export default class SupabaseClient< } this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch) - - this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime }) + this.realtime = this._initRealtimeClient({ + headers: this.headers, + accessToken: this._getAccessToken.bind(this), + ...settings.realtime, + }) this.rest = new PostgrestClient(`${_supabaseUrl}/rest/v1`, { headers: this.headers, schema: settings.db.schema, @@ -330,13 +333,9 @@ export default class SupabaseClient< (event === 'TOKEN_REFRESHED' || event === 'SIGNED_IN') && this.changedAccessToken !== token ) { - // Token has changed - this.realtime.setAuth(token ?? null) - this.changedAccessToken = token } else if (event === 'SIGNED_OUT') { - // Token is removed - this.realtime.setAuth(this.supabaseKey) + this.realtime.setAuth() if (source == 'STORAGE') this.auth.signOut() this.changedAccessToken = undefined }