mtcute/packages/client/src/methods/auth/log-out.ts

30 lines
756 B
TypeScript
Raw Normal View History

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.
*
* @param resetSession Whether to reset the session
* @returns On success, `true` is returned
* @internal
*/
export async function logOut(
this: TelegramClient,
resetSession = false
): Promise<true> {
await this.call({ _: 'auth.logOut' })
if (resetSession) {
this._userId = null
this._isBot = false
this._pts = this._seq = this._date = undefined as any
this._selfChanged = true
2021-04-08 12:19:38 +03:00
this.storage.reset()
await this._saveStorage()
2021-04-08 12:19:38 +03:00
}
return true
}