cleanup on account remove

This commit is contained in:
balzack 2024-09-26 21:21:51 -07:00
parent 92eeaa4381
commit 0c73c3380e
3 changed files with 11 additions and 14 deletions

View File

@ -53,7 +53,6 @@ export interface Settings {
unlockSeal(password: string): Promise<void>;
updaterSeal(password: string): Promise<void>;
forgetSeal(): Promise<void>;
deleteAccount(): Promise<void>;
addConfigListener(ev: (config: Config) => void): void;
removeConfigListener(ev: (config: Config) => void): void;

View File

@ -82,32 +82,27 @@ export class DatabagSDK {
public async remove(session: Session): Promise<void> {
const sessionModule = session as SessionModule;
const params = await sessionModule.close();
const { node, secure, token } = sessionModule.getParams();
await removeAccount(node, secure, token);
await sessionModule.close();
try {
await this.store.clearLogin();
}
catch(err) {
this.log.error(err);
}
try {
const { node, secure, token } = params;
await removeAccount(node, secure, token);
}
catch(err) {
this.log.error(err);
}
}
public async logout(session: Session, all: boolean): Promise<void> {
const sessionModule = session as SessionModule;
const params = await sessionModule.close();
const { node, secure, token } = sessionModule.getParams();
await sessionModule.close();
try {
await this.store.clearLogin();
}
catch(err) {
this.log.error(err);
}
const { node, secure, token } = params;
clearLogin(node, secure, token, all).then(() => {}).catch(err => {
console.log(err);
});

View File

@ -100,8 +100,13 @@ export class SessionModule implements Session {
private getStatus(): string {
return this.status;
}
public getParams(): { node: string, secure: boolean, token: string } {
const { node, secure, token } = this;
return { node, secure, token };
}
public async close(): Promise<{ node: string, secure: boolean, token: string }> {
public async close(): Promise<void> {
await this.content.close();
await this.attribute.close();
await this.alias.close();
@ -110,8 +115,6 @@ export class SessionModule implements Session {
await this.settings.close();
await this.stream.close();
this.connection.close();
const { node, secure, token } = this;
return { node: node, secure: secure, token: token };
}
public getSettings(): Settings {