1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-12-23 02:02:33 +01:00

Sync localStorage to indexedDB on startup

This commit is contained in:
nimbleghost 2023-06-17 22:08:25 +02:00
parent b7bb4459f9
commit fafe478e5c

View file

@ -11,6 +11,25 @@ class Session {
kv: "&key",
});
this.db = db;
// existing sessions (pre-v2.6.0) haven't called `store` with the session-replica,
// so attempt to sync any values from localStorage to IndexedDB
if (typeof localStorage !== "undefined" && this.exists()) {
const username = this.username();
const token = this.token();
this.db.kv
.bulkPut([
{ key: "user", value: username },
{ key: "token", value: token },
])
.then(() => {
console.log("[Session] Synced localStorage session to IndexedDB", { username });
})
.catch((e) => {
console.error("[Session] Failed to sync localStorage session to IndexedDB", e);
});
}
}
async store(username, token) {