From efae29209986ff1fe2b3b83de9b7f3f15eab2a0d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 22 Oct 2024 18:57:10 -0500 Subject: [PATCH] Fix signerMiddleware, don't throw in streamingController --- src/controllers/api/streaming.ts | 6 +----- src/middleware/signerMiddleware.ts | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index a73e2ccf..e3e5533d 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -78,11 +78,6 @@ const streamingController: AppController = async (c) => { return c.text('Please use websocket protocol', 400); } - const pubkey = await signer?.getPublicKey(); - if (!pubkey) { - return c.json({ error: 'Invalid access token' }, 401); - } - const ip = c.req.header('x-real-ip'); if (ip) { const count = limiter.get(ip) ?? 0; @@ -96,6 +91,7 @@ const streamingController: AppController = async (c) => { const store = await Storages.db(); const pubsub = await Storages.pubsub(); + const pubkey = await signer?.getPublicKey(); const policy = pubkey ? new MuteListPolicy(pubkey, await Storages.admin()) : undefined; function send(e: StreamingEvent) { diff --git a/src/middleware/signerMiddleware.ts b/src/middleware/signerMiddleware.ts index de6c859f..61507173 100644 --- a/src/middleware/signerMiddleware.ts +++ b/src/middleware/signerMiddleware.ts @@ -31,7 +31,7 @@ export const signerMiddleware: AppMiddleware = async (c, next) => { } catch { throw new HTTPException(401); } - } else { + } else if (accessToken) { try { const decoded = nip19.decode(accessToken!); @@ -47,7 +47,7 @@ export const signerMiddleware: AppMiddleware = async (c, next) => { break; } } catch { - throw new HTTPException(401); + throw new HTTPException(401, { message: 'Invalid access token' }); } }