From 64589ffb57ecbda6db2c1aa10ac0675dbf214c2c Mon Sep 17 00:00:00 2001 From: skarab42 Date: Fri, 5 Mar 2021 11:17:26 +0100 Subject: [PATCH] fix: User not resolved after seconds call (#216) Co-authored-by: skarab42 --- app/server/libs/twitch/api/getConnectedUser.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/server/libs/twitch/api/getConnectedUser.js b/app/server/libs/twitch/api/getConnectedUser.js index 122e89e..cc42aae 100644 --- a/app/server/libs/twitch/api/getConnectedUser.js +++ b/app/server/libs/twitch/api/getConnectedUser.js @@ -9,6 +9,7 @@ let reconnectDelay = 2; // seconds const logger = loggers.get("twitch"); +let connectedUser = null; let pendingConnection = { resolve: null, reject: null, @@ -37,6 +38,7 @@ async function _connect() { } state.set("userState.connected", true); state.set("userState.connecting", false); + connectedUser = user._data; resolve(user._data); } catch (error) { logger.error(`[user] ${error.stack}`); @@ -60,11 +62,11 @@ async function _connect() { module.exports = async function getConnectedUser() { if (state.get("userState.connected")) { - return Promise.resolve({ connected: true }); + return Promise.resolve(connectedUser); } if (state.get("userState.connecting")) { - return Promise.resolve({ connecting: true }); + return Promise.reject(new Error("Already connecting")); } state.set("userState.connecting", true);