diff --git a/lib/api/telegram/client.js b/lib/api/telegram/client.js index 385e929d2..87b84c5ed 100644 --- a/lib/api/telegram/client.js +++ b/lib/api/telegram/client.js @@ -24,7 +24,7 @@ export default class TelegramClientApi { #client; #events; #listeners = {}; - #authenticated; + #authenticated = true; constructor ( { apiId, apiHash, session, deviceModel, appVersion, connectionRetries = Infinity, logLevel, connect, ...options } = {} ) { this.#activityManager = new ActivityManager( { @@ -176,7 +176,13 @@ export default class TelegramClientApi { [ method ]( ...args ) // eslint-disable-line no-unexpected-multiline .then( data => result( 200, data ) ) .catch( e => { - if ( e.code === 401 ) this.#authenticated = false; + + // session terminated + if ( e.code === 401 ) { + this.#authenticated = false; + + this.#events.emit( "signout" ); + } return result.catch( e, { "log": false,