clearning session reference on logout

This commit is contained in:
balzack 2024-08-10 09:33:21 +02:00
parent 46e3f9eb4b
commit 1861f1acb2
3 changed files with 19 additions and 4 deletions

View File

@ -28,7 +28,7 @@ export interface Logging {
}
export interface Session {
close(): void;
close(): { node: string, secure: boolean, token: string };
getAccount(): Account;
getIdentity(): Identity;

View File

@ -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<void> {
session.close();
public async logout(session: Session, all: boolean): Promise<void> {
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<Node> {

View File

@ -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 {