Removed the token store
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user