fix: app doesn't work in firefox private mode

This commit is contained in:
thecodrr
2021-10-16 11:04:27 +05:00
parent 977abdb26f
commit 60da72a276

View File

@@ -42,7 +42,7 @@ async function deriveCryptoKey(name, data) {
const keyData = await crypto.deriveKey(password, salt, true); const keyData = await crypto.deriveKey(password, salt, true);
if (localforage.supports(localforage.INDEXEDDB) && window?.crypto?.subtle) { if (isIndexedDBSupported() && window?.crypto?.subtle) {
const pbkdfKey = await derivePBKDF2Key(password); const pbkdfKey = await derivePBKDF2Key(password);
await write(name, pbkdfKey); await write(name, pbkdfKey);
const cipheredKey = await aesEncrypt(pbkdfKey, keyData); const cipheredKey = await aesEncrypt(pbkdfKey, keyData);
@@ -53,7 +53,7 @@ async function deriveCryptoKey(name, data) {
} }
async function getCryptoKey(name) { async function getCryptoKey(name) {
if (localforage.supports(localforage.INDEXEDDB) && window?.crypto?.subtle) { if (isIndexedDBSupported() && window?.crypto?.subtle) {
const pbkdfKey = await read(name); const pbkdfKey = await read(name);
const cipheredKey = await read(`${name}@_k`); const cipheredKey = await read(`${name}@_k`);
if (typeof cipheredKey === "string") return cipheredKey; if (typeof cipheredKey === "string") return cipheredKey;
@@ -64,6 +64,10 @@ async function getCryptoKey(name) {
} }
} }
function isIndexedDBSupported() {
return localforage.driver() === "asyncStorage";
}
const Storage = { const Storage = {
read, read,
readMulti, readMulti,