Jump to content
McKay Development

Properly handling .logOn() in a non-stdin environment


ElijahPepe

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...