Compare commits

...

3 Commits

Author SHA1 Message Date
Gustavo Henrique Santos Souza de Miranda 3b19f58e26 fix: wait for auth session before connecting to realtime channel
On initial page load, the Supabase browser client's auth session may not
be ready yet (still loading from cookies). The Realtime channel subscription
silently fails without a valid access token. Now connect() awaits getSession()
first, which ensures the token is available and also refreshes expired tokens
on reconnect after inactivity.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 19:22:22 -03:00
Gustavo Henrique Santos Souza de Miranda 9769a80381 Merge branch 'developing' of git.gustavomiranda.xyz:GHMiranda/WebVNWrite into ralph/collaboration-and-character-variables 2026-01-24 19:15:17 -03:00
GHMiranda d2c48c0c9a Merge pull request 'ralph/collaboration-and-character-variables' (#8) from ralph/collaboration-and-character-variables into developing
Reviewed-on: #8
2026-01-24 00:00:47 +00:00
1 changed files with 15 additions and 0 deletions

View File

@ -77,6 +77,21 @@ export class RealtimeConnection {
this.resetInactivityTimer()
this.clearConnectionTimer()
// Ensure the Supabase client has a valid auth session before connecting.
// On initial page load, the session may still be loading from cookies.
try {
const { data: { session } } = await this.supabase.auth.getSession()
if (!session && !this.isDestroyed) {
// No session yet - wait briefly and retry
this.scheduleReconnect()
return
}
} catch {
// Session check failed - proceed anyway, channel will handle auth errors
}
if (this.isDestroyed || this.isPaused) return
// Set a timeout: if we don't connect within CONNECTION_TIMEOUT_MS, retry
this.connectionTimer = setTimeout(() => {
if (this.isDestroyed || this.isPaused) return