ElijahPepe Posted August 5, 2022 Report Share Posted August 5, 2022 I'm using steam-user in a project where I can't get a Steam Guard code from a user through stdin. I'm using the following code, but it's inconsistent: this.steamUser.logOn({ accountName: username, password: password, twoFactorCode: twoFactorCode }); this.steamUser.on('steamGuard', (_domain, callback) => { callback(twoFactorCode); }); this.steamUser.on('loggedOn', () => { this.steamUser.getEncryptedAppTicket(1818750, async (err, appTicket) => { if (err) { throw new Error(err); } const data = await this.info(appTicket.toString('hex')); this.accessToken = data.token; }); }); resolve(this); The above code works occasionally, but in the few times that it does work, nothing in the .getEncryptedAppTicket() block is executed. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted August 5, 2022 Report Share Posted August 5, 2022 It looks like you're passing the same code to the steamGuard event as you used in the logOn method. If it didn't work the first time, it's not going to work a second time. You likely need to wait 30 seconds for the next code to come round, or add 30 seconds to your time offset. Quote Link to comment Share on other sites More sharing options...
ElijahPepe Posted August 5, 2022 Author Report Share Posted August 5, 2022 I've set twoFactorCode to the current value in my Steam app, but the steamGuard event doesn't seem to emit and the .logOn() function doesn't seem to properly log the user in. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted August 5, 2022 Report Share Posted August 5, 2022 What output are you getting, if any? Quote Link to comment Share on other sites More sharing options...
ElijahPepe Posted August 5, 2022 Author Report Share Posted August 5, 2022 I'm not getting any output. When I console.log accessToken, null is returned. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted August 5, 2022 Report Share Posted August 5, 2022 Where are you logging accessToken? After the promise is resolved? If that's the case, you need to move your resolve(this) line after when the access token is set. I need to see all relevant code, along with debugging output (add console.log statements in places) to provide any further help. Quote Link to comment Share on other sites More sharing options...
ElijahPepe Posted August 5, 2022 Author Report Share Posted August 5, 2022 Here's the full code: return new Promise(resolve => { if (!username || !password || typeof username !== 'string' || typeof password !== 'string') { throw new Error('Invalid username or password provided.'); } this.steamUser.logOn({ accountName: username, password: password, twoFactorCode: twoFactorCode }); console.log(this.steamUser); this.steamUser.on('loggedOn', details => { console.log(details) this.steamUser.getEncryptedAppTicket(1818750, async (err, appTicket) => { console.log(appTicket); if (err) { throw new Error(err); } const data = await this.info(appTicket.toString('hex')); console.log(data); this.accessToken = data.token; }); }); resolve(this); }); this.steamUser is a construct of SteamUser. Any of the console.logs don't seem to work, although on rare occasions this.steamUser and details are logged to the console. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted August 5, 2022 Report Share Posted August 5, 2022 Your promise is getting resolved synchronously before anything actually happens. Quote Link to comment Share on other sites More sharing options...
ElijahPepe Posted August 5, 2022 Author Report Share Posted August 5, 2022 How would I make the log in process asynchronous, then? I looked at the README but couldn't find anything. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted August 6, 2022 Report Share Posted August 6, 2022 22 hours ago, Dr. McKay said: you need to move your resolve(this) line after when the access token is set. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.