diff options
Diffstat (limited to 'lib/sockets.js')
| -rw-r--r-- | lib/sockets.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sockets.js b/lib/sockets.js index 3bd0c2c2..82cf3f51 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -85,6 +85,7 @@ app.register(async function(app) { break; case "login": + let user; let token = data; if (lastSeen[token] > subtractSeconds(5)) return; lastSeen[token] = new Date(); @@ -92,7 +93,9 @@ app.register(async function(app) { try { if (!token || token === "null" || !jwt.decode(token)) return ws.close(code, `bad token ${token}`); - const { username, uuid } = jwt.decode(token); + let { username, uuid } = jwt.decode(token); + if (uuid) user = await getUser(uuid); + username = user.username; if (!(username || uuid)) throw new Error("Invalid JWT token"); if (!store.sockets[username]) store.sockets[username] = {}; @@ -110,7 +113,7 @@ app.register(async function(app) { store.sockets[username][id] = ws; names[id] = username; - let user = await getUser(username); + if (!user) user = await getUser(username); let { haspin } = user; |
