2021-04-08 12:19:38 +03:00
|
|
|
import { TelegramClient } from '../../client'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log out from Telegram account and optionally reset the session storage.
|
|
|
|
*
|
|
|
|
* When you log out, you can immediately log back in using
|
|
|
|
* the same {@link TelegramClient} instance.
|
|
|
|
*
|
|
|
|
* @returns On success, `true` is returned
|
|
|
|
* @internal
|
|
|
|
*/
|
2022-06-30 16:32:56 +03:00
|
|
|
export async function logOut(this: TelegramClient): Promise<true> {
|
2021-04-08 12:19:38 +03:00
|
|
|
await this.call({ _: 'auth.logOut' })
|
|
|
|
|
2021-07-05 17:26:30 +03:00
|
|
|
this._userId = null
|
|
|
|
this._isBot = false
|
2023-09-03 02:37:51 +03:00
|
|
|
// some implicit magic in favor of performance
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
2021-07-05 17:26:30 +03:00
|
|
|
this._pts = this._seq = this._date = undefined as any
|
|
|
|
this._selfUsername = null
|
|
|
|
this._selfChanged = true
|
|
|
|
this.storage.reset()
|
|
|
|
await this._saveStorage()
|
2021-04-08 12:19:38 +03:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|