You should check if loggedOn event's eresult is OK, otherwise there was an error logging in and therefore you can't proceed (request web session cookies). Replace:
client.on('loggedOn', function(details) {
client.getPersonas([client.steamID], function(personas) {
console.log("============ Logged in ===============================")
console.log('== Name: ' + personas[client.steamID]["player_name"]);
console.log('== ID64: ' + client.steamID);
console.log("======================================================");
console.log("");
});
console.log();
client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
setInterval(function() { client.webLogOn(); }, 1000 * 60); // Refreshes session every 10 minutes
});
with
client.on('loggedOn', function(details) {
if(details.eresult == SteamUser.EResult.OK) {
client.getPersonas([client.steamID], function(personas) {
console.log("============ Logged in ===============================")
console.log('== Name: ' + personas[client.steamID]["player_name"]);
console.log('== ID64: ' + client.steamID);
console.log("======================================================");
console.log("");
});
console.log();
client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
client.webLogOn();
} else {
console.log(details);
//Do whatever u want to handle the error...
}
});
Also, you should rate limit this:
community.on("sessionExpired", function(err) {
console.log("## Session Expired, relogging.");
client.webLogOn();
});
since it can be triggered too often and make steam temporary block your IP. You can do it like this:
var lastWebLoginAttempt = 0;
community.on("sessionExpired", function(err) {
if(Date.now() - lastLoginAttempt >= 30000) {
lastLoginAttempt = Date.now();
console.log("## Session Expired, relogging.");
client.webLogOn();
} else {
console.log("## Session Expired, waiting a while before attempting to relogin.");
}
});