diff --git a/lib/api/telegram/client.js b/lib/api/telegram/client.js index cccbf4279..385e929d2 100644 --- a/lib/api/telegram/client.js +++ b/lib/api/telegram/client.js @@ -24,6 +24,7 @@ export default class TelegramClientApi { #client; #events; #listeners = {}; + #authenticated; constructor ( { apiId, apiHash, session, deviceModel, appVersion, connectionRetries = Infinity, logLevel, connect, ...options } = {} ) { this.#activityManager = new ActivityManager( { @@ -60,6 +61,10 @@ export default class TelegramClientApi { return this.#client.connected; } + get isAuthenticated () { + return this.#authenticated; + } + // public async createSession ( { accountId, phoneCode, password } = {} ) { if ( !accountId ) { @@ -170,10 +175,13 @@ export default class TelegramClientApi { const res = await this.#client [ method ]( ...args ) // eslint-disable-line no-unexpected-multiline .then( data => result( 200, data ) ) - .catch( e => - result.catch( e, { + .catch( e => { + if ( e.code === 401 ) this.#authenticated = false; + + return result.catch( e, { "log": false, - } ) ); + } ); + } ); this.#activityManager.finishActivity();