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
630 stars 113 forks source link

Wrong unauthorized behavior #205

Closed koutsenko closed 3 years ago

koutsenko commented 3 years ago

According to official TG docs, only subset of API calls are available to unauthorized user https://core.telegram.org/api/auth#we-are-authorized

But if I try to call for example, users.getFullUser or users.getUsers, i got many "Cannot read property of undefined" library errors instead of 401 UNAUTHORIZED as described in TG docs.

I think error handling is bad. And no correct way to check am i authorized or not.

koutsenko commented 3 years ago

If the only way to check if user is authorized is sending users.getFullUser with id: { _: 'inputUserSelf' }, it must be documented. And i don't found that in official TG docs.

koutsenko commented 3 years ago

UPD: still getting errors even after "Authentication successful after entering 2FA" message

users.getFullUser error: TypeError: Cannot read property 'call' of undefined
    at Counter.predicate (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\counter\index.js:101:8)
    at Counter.users.getFullUser (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\builder\index.js:5286:10)
    at Counter.predicate (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\counter\index.js:101:8)
    at Counter.initConnection (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\builder\index.js:5625:10)
    at Counter.predicate (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\counter\index.js:101:8)
    at Counter.invokeWithLayer (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\builder\index.js:5670:10)    at new Counter (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\counter\index.js:7:8)
    at new Serializer (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\tl\serializer\index.js:7:21)
    at RPC.call (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\rpc\index.js:591:24)
    at Object.call (C:\PetProjects\mr-watson-bot\node_modules\@mtproto\core\src\index.js:106:32)
koutsenko commented 3 years ago

Found all questions by github search (keywords mtproto, language typescript) https://github.com/spalt08/telegram-js/blob/a142fd17e308f2441172278c842d26f19edceaad/src/cache/accessors.ts#L35