Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context: fix error in login after succesful delete #160

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/context/appPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ export default class AppPassword {
}
}

throw new ExtensionError(Errors.invalidAppPassword, "Invalid length.");
throw new ExtensionError(Errors.invalidAppPassword, "Invalid app-password length.");
}
}
13 changes: 10 additions & 3 deletions src/context/asyncContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,16 @@ export default class AsyncContext extends Context {
*/
async removeAndSaveProfile(name: string) {
try {
this.config.removeAndSaveProfile(name);
const success = await this.reloadContext();
return success;
await this.config.removeAndSaveProfile(name);
const leftProfileNames = this.getProfileNames();
console.log("[AsyncContext]", "Left profile names: ", leftProfileNames);
if (leftProfileNames && leftProfileNames.length > 0) {
const success = await this.reloadContext();
return success;
} else {
this.isReadyPromise = new Promise((res) => res(true));
return true;
}
} catch (err) {
throw this.parseErr(err, "Error reloading context.");
}
Expand Down
19 changes: 18 additions & 1 deletion src/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export class Config {
}

this.save();
await this.removeKeychainPassword(name);

if (newProfileName) {
this.setProfile(newProfileName);
Expand Down Expand Up @@ -276,7 +277,6 @@ export class Config {
resolve();
}
};

keychain.setPassword({
account,
password: appPassword,
Expand All @@ -286,6 +286,23 @@ export class Config {
});
}

/// Removes an app-password from the keychain
async removeKeychainPassword(account: string): Promise<void> {
return new Promise((resolve, reject) => {
const cb = (err: KeychainError): void => {
if (err) {
reject(err);
} else {
resolve();
}
};
keychain.deletePassword({
account,
service: KEYCHAIN_SERVICE,
}, cb);
});
}

/// Gets a keychain app-password for a profile
async getKeychainPassword(account: string): Promise<string> {
return new Promise((resolve, reject) => {
Expand Down
Loading