From d02794998ec2be9f2d5fd7586b3d85f84f0ebd0a Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Fri, 23 Feb 2024 10:57:39 -0800 Subject: [PATCH] Change how events are re-sent when auth is done --- src/ConnectionMeta.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ConnectionMeta.ts b/src/ConnectionMeta.ts index 1e4dbe0..bc870d7 100644 --- a/src/ConnectionMeta.ts +++ b/src/ConnectionMeta.ts @@ -94,11 +94,18 @@ export class ConnectionMeta { this.pendingPublishes.set(event.id, {sent: Date.now(), event}) } - onReceiveOk([verb, eventId, ok]: Message) { + onReceiveOk([verb, eventId, ok, notice]: Message) { const publish = this.pendingPublishes.get(eventId) if (ok) { this.authStatus = AuthStatus.Ok + } else if (notice.startsWith('auth-required:')) { + // Re-enqueue pending reqs when auth challenge is received + const pub = this.pendingPublishes.get(eventId) + + if (pub) { + this.cxn.send(['EVENT', pub.event]) + } } if (publish) { @@ -130,14 +137,8 @@ export class ConnectionMeta { } onReceiveClosed([verb, id, notice]: Message) { - // Re-enqueue pending reqs/events when auth challenge is received if (notice.startsWith('auth-required:')) { - const pub = this.pendingPublishes.get(id) - - if (pub) { - this.cxn.send(['EVENT', pub.event]) - } - + // Re-enqueue pending reqs when auth challenge is received const req = this.pendingRequests.get(id) if (req) {