Skip to content

Commit 9a25262

Browse files
committed
fix(realtime): eliminate race condition in custom JWT token authentication
1 parent fedbeeb commit 9a25262

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
@@ -191,6 +191,13 @@ export default class RealtimeClient {
191191

192192
this._setConnectionState('connecting')
193193

194+
// Trigger auth if needed and not already in progress
195+
// This ensures auth is called for standalone RealtimeClient usage
196+
// while avoiding race conditions with SupabaseClient's immediate setAuth call
197+
if (this.accessToken && !this._authPromise) {
198+
this._setAuthSafely('connect')
199+
}
200+
194201
// Establish WebSocket connection
195202
if (this.transport) {
196203
// Use custom transport if provided

0 commit comments

Comments
 (0)