Jump to content
McKay Development

ElijahPepe

Member
  • Posts

    6
  • Joined

  • Last visited

Posts posted by ElijahPepe

  1. I have two functions in a class:

    login(username, password) {
    	this.steamUser.logOn({ accountName: username, password: password });
    	this.steamUser.on('loggedOn', async () => {
    		await this._getAccessToken();
    		return this.accessToken;
    	});
    }
    
    _getAccessToken() {
    	return new Promise(resolve => {
    		this.steamUser.getEncryptedAppTicket(1818750, async (err, appTicket) => {
    			if (err) {
    				throw new Error(err);
    			}
    
    			const data = await this.info(appTicket.toString('hex').toUpperCase());
    			this.accessToken = data.token;
    
    			resolve(this);
    		});
    	});
    }

    When I call the login() function, .logOn() is resolved before the loggedOn event can be fired. Is there a way of using .logOn() asynchronously?

  2. 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.

  3. 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?

×
×
  • Create New...