Jump to content
McKay Development

Using these libraries in server-less environments/functions


nickmura aka bobby

Recommended Posts

Hello, I'm trying to refactor my service in Svelte-kit, and I've been running into quite tedious errors when testing and initializing a user.

Here is a quick test when a user sends a post request, which would initialize the user, run some business logic, and then log off. 

I've ran essentially the same code in an express environment, with the same environment variables, which worked fine.

export const POST = async ({request:request}) => {
  //TODO

  const client = new SteamUser();
  const community = new SteamCommunity();
  const manager = new TradeOfferManager({
    steam: client,
    community: community,
    language: 'en',
  });

  const cred = {
    accountName: STEAM_NAME,
    password: STEAM_PASS,
    twoFactorCode: SteamTotp.generateAuthCode(STEAM_SHARED),
    logonID: 12345
  };


  client.logOn(cred); // logging on 
  client.on('loggedOn', async () => {
    console.log('logged into steam');
    client.setPersona(SteamUser.EPersonaState.Online)
  })

  client.on('webSession', (sessionid, cookies) => {
    manager.setCookies(cookies);
    community.setCookies(cookies);
    community.startConfirmationChecker(12500, STEAM_IDENTITY);
  })
  
  async function doTradeStuff() {
    //TODO
  } //await doTradeStuff()
  
  client.logOff(); // logging off

  client.on('disconnected', async (eresult, msg) => {
    console.log('logged off steam', eresult, msg)
  })

  return json({place: 'holder'})
}

Firstly, in all of the iterations I've made, I keep getting this `Error: LogonSessionReplaced 34`, which your documentation states could be mitigated / prevented by the logonID property when using the logOn method https://github.com/DoctorMcKay/node-steam-user#logondetails. However the issue still persists.

 

Secondly, the logOff method never runs in the serverless environment, as I do not get a disconnected event. https://github.com/DoctorMcKay/node-steam-user#disconnected

 

So, I'm looking for any guidance / hint as to where to look,  where I'm going wrong, if there's better practice, what to be aware about if I'm trying to run this in a serverless environment, etc. Thanks for your libraries. 

Edited by nickmura aka bobby
'logOff function' to 'logOff method'
Link to comment
Share on other sites

Using steam-user in a serverless environment is really not a good idea, unless your environment runs very infrequently.

the logOff() method isn't doing anything for you because you're calling it synchronously right after logOn(). logOff() does nothing if not already logged on. You'd need to call client.logOff() inside your doTradeStuff method, at the end after everything has been done.

Link to comment
Share on other sites

7 minutes ago, Dr. McKay said:

Using steam-user in a serverless environment is really not a good idea, unless your environment runs very infrequently.

the logOff() method isn't doing anything for you because you're calling it synchronously right after logOn(). logOff() does nothing if not already logged on. You'd need to call client.logOff() inside your doTradeStuff method, at the end after everything has been done.

The test successfully logs in, and logOff is not an asynchronous method I thought?
Anyways, your opinion is much better than mine, and if it's not a good idea to have a serverless backend, then I don't need to log out I guess. do you think you could you elaborate a bit on why it's bad? Thx

Edited by nickmura aka bobby
Link to comment
Share on other sites

logOff() is not async, no. But you're calling it before you're actually logged on, because you're calling it synchronously along with logOn().

A couple reasons why running steam-user serverless is a bad idea:

  1. You can only log on once every 30 seconds because that's how frequently TOTP codes change
  2. Steam will start throttling your logon attempts, even if you don't have any failed logons
  3. Your request responses will take quite a long time with all the overhead of logging on each time
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...