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' }); } }