alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
632 stars 116 forks source link

Nothing happens after calling auth.signIn #36

Closed Eonus21 closed 4 years ago

Eonus21 commented 4 years ago

I just copy login example, and have problem. Nothings happens after calling auth.signIn. All code which i try is below. I try it with such versions as

And then nothing happens after two minutes, even so Telegram send me message about new logged device

const { MTProto, getSRPParams } = require('@mtproto/core');
const readline = require('readline');
var cl = readline.createInterface( process.stdin, process.stdout );
var question = function(q) {
    return new Promise( (res, rej) => {
        cl.question( q, answer => {
            res(answer);
        })
    });
};

const mtproto = new MTProto({
  api_id: ,
  api_hash: '',
  test: false
});

const phone = '';
const password = '';

function sendCode(phone) {
  return mtproto.call('auth.sendCode', {
    phone_number: phone,
    settings: {
      _: 'codeSettings',
    },
  });
}

let code_hash

sendCode(phone)
  .catch(error => {
    if (error.error_message.includes('_MIGRATE_')) {
      const [type, nextDcId] = error.error_message.split('_MIGRATE_');

      mtproto.setDefaultDc(+nextDcId);

      return sendCode(phone);
    }
    else return sendCode(phone);
  })
  .then(result => {
      code_hash = result.phone_code_hash
      return question('Code')
  })
  .then(code => {
    return mtproto.call('auth.signIn', {
      phone_code: code,
      phone_number: phone,
      phone_code_hash: code_hash,
    });
   //after this part nothing happens
  })
  .catch(error => {
    if (error.error_message === 'SESSION_PASSWORD_NEEDED') {
      return mtproto.call('account.getPassword').then(async result => {
        const { srp_id, current_algo, srp_B } = result;
        const { salt1, salt2, g, p } = current_algo;

        const { A, M1 } = await getSRPParams({
          g,
          p,
          salt1,
          salt2,
          gB: srp_B,
          password,
        });

        return mtproto.call('auth.checkPassword', {
          password: {
            _: 'inputCheckPasswordSRP',
            srp_id,
            A,
            M1,
          },
        });
      });
    }
  })
  .then(result => {
    console.log('auth.authorization:', result);
  })
Eonus21 commented 4 years ago

It was once successfully, with version 3.0.0

anhnhoktvn commented 4 years ago

I have the same problem. However, it worked with test server.

alik0211 commented 4 years ago

Guys, now try set syncAuth to false for auth.signIn and auth.checkPassword. I will look for the error tomorrow

sami286 commented 4 years ago

Guys, now try set syncAuth to false for auth.signIn and auth.checkPassword. I will look for the error tomorrow

Doesn't work with syncAuth: false either, keeps giving me the same response:

signInResponse: {
    _: 'auth.authorizationSignUpRequired',
    pFlags: {},
    flags: 1,
    terms_of_service: {
      _: 'help.termsOfService',
      pFlags: [Object],
      flags: 1,
      id: [Object],
      text: 'You must be at least 16 years old to sign up. By signing up for Telegram, you agree not to:\n' +
        '\n' +
        '- Use our service to send spam or scam users.\n' +
        '- Promote violence on publicly viewable Telegram bots, groups or channels.\n' +
        '- Post illegal pornographic content on publicly viewable Telegram bots, groups or channels.\n' +
        '\n' +
        'We reserve the right to update these Terms of Service later.\n' +
        '\n' +
        'By proceeding, you are accepting these Terms and our Privacy Policy.',
      entities: [Array]
    }
  }

The phone number I used is registered and has an account associated with it, so auth.authorizationSignUpRequired makes no sense...

alik0211 commented 4 years ago

@sami286 You may be logging in to test servers. And you need to register separately on test servers

To log in to the main Telegram servers comment the test flag:

const mtproto = new MTProto({
  api_id: process.env.API_ID,
  api_hash: process.env.API_HASH,

  // test: true,
});
sami286 commented 4 years ago

@sami286 You may be logging in to test servers. And you need to register separately on test servers

To log in to the main Telegram servers comment the test flag:

const mtproto = new MTProto({
  api_id: process.env.API_ID,
  api_hash: process.env.API_HASH,

  // test: true,
});

Thanks, that was exactly my problem :) I apologise for commenting with irrelevant info, I thought it could be related to the issue

alik0211 commented 4 years ago

@IIE4EHbKAKOKC wait more than two minutes. The library syncs authorization on all DC's (this may take several minutes). Or disable it: set syncAuth to false for auth.signIn and auth.checkPassword

  1. Log and show all results from .then blocks
  2. Log and show all errors from .catch blocks
  3. Use latest library version
somgupta13 commented 4 years ago

@alik0211 actually i need to use the 'auth.exportAuthorisation' so i need it syncs authorisation on all dc's but it is taking more my result is on hold

alik0211 commented 4 years ago

@somgupta13 I answered you in another issue - https://github.com/alik0211/mtproto-core/issues/41#issuecomment-623541395

alik0211 commented 4 years ago

@IIE4EHbKAKOKC if you don't send an info by may 11 I'll close the issue

alik0211 commented 4 years ago

This error is probably fixed in version 3.1.1. View more: https://t.me/mtproto_core/17