realtime: bail in connect() when getToken returns no token

Without a JWT the Phoenix TenantSocket refuses the handshake
("REFUSED CONNECTION TO ArcadiaWeb.TenantSocket"), the client retries
forever, and both ends spam logs. Consumers like skyai-ecosystem set
enableRealtime unconditionally at mount, before login completes, which
is the common case for this noise.

Callers should invoke connect() again after login (e.g. on
crema:session-change) — the existing reconnect path covers that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
jules
2026-05-16 22:17:54 +10:00
parent 70803b9f60
commit 57dc0455d1

View File

@@ -110,6 +110,16 @@ export function createArcadiaRealtime(opts: ArcadiaRealtimeOptions): ArcadiaReal
setStatus("connecting");
const token = await opts.getToken();
// No session → don't open the socket. Phoenix would refuse the
// handshake on the server (TenantSocket.connect/3 requires a JWT)
// and the client would retry forever, spamming both ends. Callers
// should invoke connect() again after login (e.g. on
// `crema:session-change`).
if (!token) {
setStatus("idle");
return;
}
const factory =
opts.socketFactory ?? ((endpoint, o) => new Socket(endpoint, o));