25 lines
491 B
TypeScript
25 lines
491 B
TypeScript
// Utilities
|
|
import {defineStore} from 'pinia'
|
|
|
|
export const useAppStore = defineStore('app', {
|
|
state: () => ({
|
|
user: null,
|
|
}),
|
|
actions: {
|
|
async updateUser() {
|
|
const res = await fetch('/gui/auth/me')
|
|
if (res.status === 200) {
|
|
const data = await res.json()
|
|
|
|
if (data.loggedIn) {
|
|
this.user = data.user
|
|
} else {
|
|
this.user = null
|
|
}
|
|
} else if (res.status === 401) {
|
|
this.user = null
|
|
}
|
|
}
|
|
}
|
|
})
|