summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-02 21:05:27 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-02 21:05:27 +1000
commit09f5b4f0bbb4d88e97d75dc014f549f2571cc135 (patch)
treee7d773e383d9535892144077e44607e405c7b44a
parentsentry db instrumentation for gateway events (diff)
downloadserver-09f5b4f0bbb4d88e97d75dc014f549f2571cc135.tar.xz
Fix identify throwing on invalid token instead of closing with auth failed close code
-rw-r--r--src/gateway/opcodes/Identify.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts

index e097e44c..9a3128d9 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -60,6 +60,14 @@ import { check } from "./instanceOf"; // TODO: user sharding // TODO: check privileged intents, if defined in the config +const tryGetUserFromToken = async (...args: Parameters<typeof checkToken>) => { + try { + return (await checkToken(...args)).user; + } catch (e) { + return null; + } +}; + export async function onIdentify(this: WebSocket, data: Payload) { if (this.user_id) { // we've already identified @@ -74,7 +82,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { this.capabilities = new Capabilities(identify.capabilities || 0); - const { user } = await checkToken(identify.token, { + const user = await tryGetUserFromToken(identify.token, { relations: ["relationships", "relationships.to", "settings"], select: [...PrivateUserProjection, "relationships"], });