Restore logged-in state on page reload
This commit is contained in:
parent
ffc1c6806a
commit
290218eefe
|
@ -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
8
client/src/util.ts
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue