diff --git a/app/sdk/src/api.ts b/app/sdk/src/api.ts index 19bdf4f1..bce9043d 100644 --- a/app/sdk/src/api.ts +++ b/app/sdk/src/api.ts @@ -28,7 +28,7 @@ export interface Logging { } export interface Session { - close(): void; + close(): { node: string, secure: boolean, token: string }; getAccount(): Account; getIdentity(): Identity; diff --git a/app/sdk/src/index.ts b/app/sdk/src/index.ts index ce67ad1f..741e679c 100644 --- a/app/sdk/src/index.ts +++ b/app/sdk/src/index.ts @@ -4,6 +4,7 @@ import { BotModule } from './bot'; import { ConsoleLogging } from './logging'; import { type Store, OfflineStore, OnlineStore, NoStore } from './store'; import { setLogin } from './net/setLogin'; +import { clearLogin } from './net/clearLogin'; import { setAccess } from './net/setAccess'; import { addAccount } from './net/addAccount'; import { setAdmin } from './net/setAdmin'; @@ -64,8 +65,21 @@ export class DatabagSDK { return new SessionModule(this.store, this.crypto, this.log, appToken, node, secure, created); } - public async logout(session: Session): Promise { - session.close(); + public async logout(session: Session, all: boolean): Promise { + const params = session.close(); + try { + const { node, secure, token } = params; + await clearLogin(node, secure, token, all); + } + catch(err) { + console.log(err); + } + try { + await this.store.clearLogin(); + } + catch(err) { + console.log(err); + } } public async configure(node: string, secure: boolean, token: string, mfaCode: string | null): Promise { diff --git a/app/sdk/src/session.ts b/app/sdk/src/session.ts index 5424eae6..986220fc 100644 --- a/app/sdk/src/session.ts +++ b/app/sdk/src/session.ts @@ -131,7 +131,7 @@ export class SessionModule implements Session { } } - public close() { + public close(): { node: string, secure: boolean, token: string } { this.connection.close(); this.stream.close(); this.content.close(); @@ -140,6 +140,7 @@ export class SessionModule implements Session { this.contact.close(); this.identity.close(); this.account.close(); + return { node: this.node, secure: this.secure, token: this.token }; } public getAccount(): Account {