DoctorMcKay / node-steamcommunity

Interact with various interfaces on Steam Community from Node.js
https://dev.doctormckay.com/forum/8-node-steamcommunity/
MIT License
475 stars 128 forks source link

community.steamID is missing (undefined) even though logged in. #324

Closed goodluckgod closed 1 year ago

goodluckgod commented 1 year ago

Hello,

First of all, I did not create a topic in the forum because I thought this was a bug. I could be wrong, sorry in advance.

I am trying to login to my steam user (bot) with proxies via node-steamcommunity, but sometimes the login function returning without any error and i can use other variables. Sometimes i can login to bot without any error.

Here is the function of login method;

const loginToBot = async (bot: ISteamBot) => {
  const proxyUrl = await getBestProxy({
    protocol: EProxyProtocol.HTTP,
  });

  return new Promise<
    Omit<
      ISteamContainer,
      | "tradeOfferManager"
      | "trustScore"
      | "increaseTrustScore"
      | "decreaseTrustScore"
    >
  >((resolve, reject) => {
    const community = new SteamCommunity({
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      request: proxyUrl
        ? request.defaults({
            proxy: proxyUrl,
          })
        : request,
    });
    community.login(
      {
        accountName: bot.username,
        password: bot.password,
        twoFactorCode: SteamTotp.generateAuthCode(bot.sharedSecret),
      },
      async (err, sessionID, cookies, steamguard, oAuthToken) => {
        if (err) {
          return reject(err);
        }

        if (!community.steamID) {
          // debug
          console.log(err, sessionID, cookies, steamguard, oAuthToken);
          return reject(new AppError("NO_STEAM_ID", `Bot: ${bot.username}`));
        }

        const user = (await new Promise((resolve, reject) => {
          community.getSteamUser(community.steamID, (err, user) => {
            if (err) {
              return reject(err);
            }

            return resolve(user);
          });
        })) as CSteamUser;

        return resolve({
          community,
          cookies,
          sessionID,
          steamguard,
          oAuthToken,
          sharedSecret: bot.sharedSecret,
          identitySecret: bot.identitySecret,
          tradeUrl: bot.tradeUrl,
          _id: bot._id,
          information: {
            steamId: community.steamID.toString(),
            username: bot.username,
            name: user.name,
            avatar: void user.getAvatarURL() || "",
          },
        });
      }
    );
  });
};

I am getting "NO_STEAM_ID" in this function and situation

Here is the console output;

image

If the bot cannot logged in why i can't see any error?

Thanks.

zyoi commented 1 year ago

Check my comment on the other issue

https://github.com/DoctorMcKay/node-steamcommunity/issues/323#issuecomment-1771545192

goodluckgod commented 1 year ago

Check my comment on the other issue

#323 (comment)

I will try soon, thanks so much!

DoctorMcKay commented 1 year ago

Duplicate of #321