Skip to content

Commit 793bbde

Browse files
committed
fix(realtime): eliminate race condition in custom JWT token authentication
1 parent 04ce093 commit 793bbde

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/core/realtime-js/src/RealtimeClient.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ export default class RealtimeClient {
187187

188188
this._setConnectionState('connecting')
189189

190+
// Trigger auth if needed and not already in progress
191+
// This ensures auth is called for standalone RealtimeClient usage
192+
// while avoiding race conditions with SupabaseClient's immediate setAuth call
193+
if (this.accessToken && !this._authPromise) {
194+
this._setAuthSafely('connect')
195+
}
196+
190197
// Establish WebSocket connection
191198
if (this.transport) {
192199
// Use custom transport if provided

0 commit comments

Comments
 (0)