Skip to content

Commit

Permalink
fix: User not resolved after seconds call (#216)
Browse files Browse the repository at this point in the history
Co-authored-by: skarab42 <skarab@onlfait.ch>
  • Loading branch information
skarab42 and skarab42 authored Mar 5, 2021
1 parent 56a861b commit 64589ff
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/server/libs/twitch/api/getConnectedUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let reconnectDelay = 2; // seconds

const logger = loggers.get("twitch");

let connectedUser = null;
let pendingConnection = {
resolve: null,
reject: null,
Expand Down Expand Up @@ -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}`);
Expand All @@ -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);
Expand Down

0 comments on commit 64589ff

Please sign in to comment.