Restore logged-in state on page reload

This commit is contained in:
D. Scott Boggs 2023-08-26 05:48:44 -04:00
parent ffc1c6806a
commit 290218eefe
2 changed files with 11 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import { reactive } from "vue"
import { Track } from "./track"
import { Tick } from './ticks'
import { error } from "./error"
import { getCookie } from "./util";
enum State {
Unfetched,
@ -31,6 +32,8 @@ class AppState {
constructor() {
this.tracks = new Array<Track>
this.state = State.Unfetched
const name = getCookie("name")
if (name) this.user = { name }
}
streamUpdatesFromServer() {
const source = new EventSource("/api/v1/updates")

8
client/src/util.ts Normal file
View file

@ -0,0 +1,8 @@
export function getCookie(key: string): string | null {
const start = document.cookie.indexOf(key + '=')
if(start === -1) return null
let end: number | undefined = document.cookie.indexOf(';', start)
if(end === -1)
end = undefined
return document.cookie.substring(start + key.length + 1, end)
}