Fix identify throwing on invalid token instead of closing with auth failed close code
This commit is contained in:
parent
2fc3c5dbd4
commit
09f5b4f0bb
@ -60,6 +60,14 @@ import { check } from "./instanceOf";
|
|||||||
// TODO: user sharding
|
// TODO: user sharding
|
||||||
// TODO: check privileged intents, if defined in the config
|
// 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) {
|
export async function onIdentify(this: WebSocket, data: Payload) {
|
||||||
if (this.user_id) {
|
if (this.user_id) {
|
||||||
// we've already identified
|
// we've already identified
|
||||||
@ -74,7 +82,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
|
|
||||||
this.capabilities = new Capabilities(identify.capabilities || 0);
|
this.capabilities = new Capabilities(identify.capabilities || 0);
|
||||||
|
|
||||||
const { user } = await checkToken(identify.token, {
|
const user = await tryGetUserFromToken(identify.token, {
|
||||||
relations: ["relationships", "relationships.to", "settings"],
|
relations: ["relationships", "relationships.to", "settings"],
|
||||||
select: [...PrivateUserProjection, "relationships"],
|
select: [...PrivateUserProjection, "relationships"],
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user