Removed the token store

This commit is contained in:
2026-09-07 23:55:57 +03:00
parent 817d61a663
commit cddfc1e24b
8 changed files with 62 additions and 69 deletions
+26
View File
@@ -0,0 +1,26 @@
const LOCAL_STORAGE_KEY="token"
export const Anonymous = Symbol("anonymous")
class Token {
constructor({token, expiresAt}) {
this.token = token
this.expiresAt = new Date(expiresAt)
}
}
export function loadToken() {
let data = localStorage[LOCAL_STORAGE_KEY]
if (data == null) { return Anonymous }
data = JSON.parse(data)
if (data == null || data.token == null) { return Anonymous }
let token = new Token(data)
if(token.expiresAt < new Date()) { return Anonymous }
return token
}
export function saveToken(value) {
if(value == null || !value.token) return;
localStorage[LOCAL_STORAGE_KEY] = JSON.stringify(value)
}