mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Streaming: handle token errors as 401s
This commit is contained in:
parent
ba8b7ecaea
commit
93a035e3ff
1 changed files with 8 additions and 3 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue