mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-22 11:24:04 +01:00
Sync localStorage to indexedDB on startup
This commit is contained in:
parent
b7bb4459f9
commit
fafe478e5c
1 changed files with 19 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue