Streaming: handle token errors as 401s

This commit is contained in:
Alex Gleason 2025-01-20 22:47:21 -06:00
parent ba8b7ecaea
commit 93a035e3ff
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -18,6 +18,7 @@ import { getTokenHash } from '@/utils/auth.ts';
import { bech32ToPubkey, Time } from '@/utils.ts'; import { bech32ToPubkey, Time } from '@/utils.ts';
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts'; import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
import { renderNotification } from '@/views/mastodon/notifications.ts'; import { renderNotification } from '@/views/mastodon/notifications.ts';
import { HTTPException } from '@hono/hono/http-exception';
const console = new Stickynotes('ditto:streaming'); const console = new Stickynotes('ditto:streaming');
@ -236,13 +237,17 @@ async function getTokenPubkey(token: string): Promise<string | undefined> {
const kysely = await Storages.kysely(); const kysely = await Storages.kysely();
const tokenHash = await getTokenHash(token as `token1${string}`); const tokenHash = await getTokenHash(token as `token1${string}`);
const { pubkey } = await kysely const row = await kysely
.selectFrom('auth_tokens') .selectFrom('auth_tokens')
.select('pubkey') .select('pubkey')
.where('token_hash', '=', tokenHash) .where('token_hash', '=', tokenHash)
.executeTakeFirstOrThrow(); .executeTakeFirst();
return pubkey; if (!row) {
throw new HTTPException(401, { message: 'Invalid access token' });
}
return row.pubkey;
} else { } else {
return bech32ToPubkey(token); return bech32ToPubkey(token);
} }