From 965a9852acf939b4da3c418b31fdc4c117efb004 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Mon, 1 Mar 2021 15:10:51 -0600 Subject: send 401 status code when unauthorized --- build/hypixelCached.js | 10 +++++++--- build/index.js | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'build') diff --git a/build/hypixelCached.js b/build/hypixelCached.js index 48b8ff0..ccb0ca6 100644 --- a/build/hypixelCached.js +++ b/build/hypixelCached.js @@ -67,7 +67,7 @@ function waitForSet(cache, key, value) { const listener = (setKey, setValue) => { if (setKey === key || (value && setValue === value)) { cache.removeListener('set', listener); - return resolve({ key, value }); + return resolve({ key: setKey, value: setValue }); } }; cache.on('set', listener); @@ -86,7 +86,9 @@ async function uuidFromUser(user) { const username = usernameCache.get(util_1.undashUuid(user)); // if it has .then, then that means its a waitForSet promise. This is done to prevent requests made while it is already requesting if (username.then) { - return (await username).key; + const { key: uuid, value: _username } = await username; + usernameCache.set(uuid, _username); + return uuid; } else return util_1.undashUuid(user); @@ -103,8 +105,10 @@ async function uuidFromUser(user) { usernameCache.set(util_1.undashUuid(user), waitForSet(usernameCache, user, user)); // not cached, actually fetch mojang api now let { uuid, username } = await mojang.mojangDataFromUser(user); - if (!uuid) + if (!uuid) { + usernameCache.set(uuid, null); return; + } // remove dashes from the uuid so its more normal uuid = util_1.undashUuid(uuid); if (user !== uuid) diff --git a/build/index.js b/build/index.js index e6d0ff3..11b2fc6 100644 --- a/build/index.js +++ b/build/index.js @@ -12,8 +12,7 @@ exports.debug = false; app.use((req, res, next) => { if (process.env.key && req.headers.key !== process.env.key) // if a key is set in process.env and the header doesn't match return an error - // TODO: make this have a status code - return res.json({ error: 'Key in header must match key in env' }); + return res.status(401).json({ error: 'Key in header must match key in env' }); next(); }); app.get('/', async (req, res) => { -- cgit