diff options
| author | Adam Soltys <[email protected]> | 2020-08-05 11:28:39 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-08-05 11:28:39 -0700 |
| commit | 77570348c3127ea59b910979bab8152eebbb7946 (patch) | |
| tree | 32c09a4e7ba7b9be9b52c8b5def7fe05e9f6a8d4 /lib | |
| parent | 2717860daf920b14eaa6859832de8ba26f239d06 (diff) | |
| download | coinos-server-77570348c3127ea59b910979bab8152eebbb7946.tar.gz coinos-server-77570348c3127ea59b910979bab8152eebbb7946.zip | |
move token check
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sockets.js | 4 |
1 files changed, 3 insertions, 1 deletions
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) { |
