From 77570348c3127ea59b910979bab8152eebbb7946 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 5 Aug 2020 11:28:39 -0700 Subject: move token check --- lib/sockets.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sockets.js b/lib/sockets.js index fc9ab87f..e5816edd 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -60,9 +60,11 @@ wss.on("connection", function (ws, req) { switch (type) { case "login": let token = data; - if (!token || token === "null") return; try { + if (!token || token === "null") throw new Error("Unauthorized socket login"); const username = jwt.decode(token).username; + if (!username) throw new Error("Invalid JWT token"); + if (!sockets[username]) sockets[username] = {}; const existing = Object.keys(sockets[username]); if (existing.length > 5) { -- cgit v1.2.3