import {$user, setAnonUser, setLoggedInUser} from "../stores/user.js"; const LOCAL_STORAGE_KEY="user" $user.subscribe(value => { if(value == null || !value.initialized) return; localStorage[LOCAL_STORAGE_KEY] = JSON.stringify(value) }) window.addEventListener('load', () => { let data = localStorage[LOCAL_STORAGE_KEY] if (data == null) { return setAnonUser() } data = JSON.parse(data) if (data == null || data.token == null) { return setAnonUser() } if(Date.parse(data.expiresAt) < Date()) { return setAnonUser() } setLoggedInUser(data.token, data.expiresAt) })