Skip to content

Commit

Permalink
fix: Bind proper object to setAuth on Realtime callback (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco authored Dec 9, 2024
1 parent 0ea6d8f commit 325c2c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 6 additions & 7 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 325c2c9

Please sign in to comment.