Good day. Here is a function I have:
function LoginClient(user) {
return new Promise((resolve, reject) => {
SteamClients[user.username].client.logOn({
accountName: SteamClients[user.username].details.username,
password: SteamClients[user.username].details.password,
twoFactorCode: SteamTotp.generateAuthCode(SteamClients[user.username].details.shared_secret)
})
SteamClients[user.username].client.on('loggedOn', ()=> {
Debug.emit('message', `Client logged in: ${SteamClients[user.username]}`);
})
SteamClients[user.username].client.on('webSession', (sid, cookies)=> {
manager.setCookies(cookies);
community.setCookies(cookies);
Debug.emit('message', `Client logged into websession: ${SteamClients[user.username]}`);
})
})
}
What I want to achieve with this function is that when the client is logged on and so is the websession, only then is the promise resolved. The reason why is because timing is important.