diff options
| author | Adam Soltys <[email protected]> | 2023-04-16 18:14:36 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-04-16 18:16:59 +0000 |
| commit | e1beafc2c1add04495fe31475aa344c5219e525c (patch) | |
| tree | e76df5d71c5fa16d3a17a40ec384ed0f275159ea /lib/sockets.js | |
| parent | d404f11e5df3c982ed91e4cddd2fbc9de6870262 (diff) | |
| download | coinos-server-e1beafc2c1add04495fe31475aa344c5219e525c.tar.gz coinos-server-e1beafc2c1add04495fe31475aa344c5219e525c.zip | |
ip and lnurl fixes
Diffstat (limited to 'lib/sockets.js')
| -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 e5f2638b..c42c9c7a 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -49,17 +49,19 @@ export const broadcast = (type, data) => { let track = async (ws, token) => { let { id } = ws; let { id: uid } = jwt.decode(token); + if (!uid) throw new Error("Invalid JWT token"); let user = await g(`user:${uid}`); if (!user) throw new Error("User not found"); if (!store.sockets[uid]) store.sockets[uid] = {}; - if (store.sockets[uid][id]) return; + const existing = Object.keys(store.sockets[uid]); if (existing.length > 4) { const p = existing.find(sid => sid !== uid); store.sockets[uid][p].close(code, "too many sockets"); } + store.sockets[uid][id] = ws; users[id] = uid; ws.user = user; |
