]> zoso.dev Git - libnemo.git/commitdiff
Session storage operations are synchronous, so wrap them in Promises to at least...
authorChris Duncan <chris@zoso.dev>
Mon, 14 Oct 2024 09:43:05 +0000 (02:43 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 14 Oct 2024 09:43:05 +0000 (02:43 -0700)
src/lib/safe.ts

index 7d9ae7babc3397777fe2992e2c122bee23b28dc5..6a2d3c8be586f201ced1ae145c5a4c1f6df0fa25 100644 (file)
@@ -58,7 +58,14 @@ export class Safe {
         encrypted: buffer.toHex(encrypted),
         iv: iv.hex
       }
-      storage.setItem(name, JSON.stringify(record))
+      await new Promise<void>((resolve, reject) => {
+        try {
+          storage.setItem(name, JSON.stringify(record))
+          resolve()
+        } catch (err) {
+          reject(err)
+        }
+      })
       passkey = ''
     } catch (err) {
       throw new Error(ERR_MSG)
@@ -79,7 +86,9 @@ export class Safe {
       return null
     }
 
-    const item = storage.getItem(name)
+    const item = await new Promise<string | null>(resolve => {
+      resolve(storage.getItem(name))
+    })
     if (item == null) {
       return null
     }