Fix signerMiddleware, don't throw in streamingController

This commit is contained in:
Alex Gleason 2024-10-22 18:57:10 -05:00
parent 6a63724864
commit efae292099
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 3 additions and 7 deletions

View file

@ -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) {

View file

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