From f1b533f7b656199b276d5d94b18836984f1e2156 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Mon, 31 Oct 2022 20:04:13 +1000 Subject: [PATCH] Handle falsy values in keytarSecureStorageService (#286) --- .github/workflows/build.yml | 1 + src/services/keytarSecureStorage.service.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5b0dc2e..b7a1354c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,6 +101,7 @@ jobs: - name: Version Test run: | + sudo apt-get update sudo apt install libsecret-1-0 dbus-x11 gnome-keyring eval $(dbus-launch --sh-syntax) diff --git a/src/services/keytarSecureStorage.service.ts b/src/services/keytarSecureStorage.service.ts index faadcde5..be06aa49 100644 --- a/src/services/keytarSecureStorage.service.ts +++ b/src/services/keytarSecureStorage.service.ts @@ -16,6 +16,12 @@ export class KeytarSecureStorageService implements StorageService { } save(key: string, obj: any): Promise { + // keytar throws if you try to save a falsy value: https://github.com/atom/node-keytar/issues/86 + // handle this by removing the key instead + if (!obj) { + return this.remove(key); + } + return setPassword(this.serviceName, key, JSON.stringify(obj)); }