DUNGEONS-34: implement Webka local streaming app
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
31
frontend/stores/session.ts
Normal file
31
frontend/stores/session.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { defineStore } from "pinia";
|
||||
export interface User {
|
||||
id: string;
|
||||
username: string;
|
||||
role: "admin" | "viewer";
|
||||
session_id: string;
|
||||
}
|
||||
export const useSessionStore = defineStore("session", () => {
|
||||
const user = ref<User | null>(null);
|
||||
const ready = ref(false);
|
||||
async function refresh() {
|
||||
try {
|
||||
user.value = await $fetch<User>("/api/session");
|
||||
return true;
|
||||
} catch {
|
||||
user.value = null;
|
||||
return false;
|
||||
} finally {
|
||||
ready.value = true;
|
||||
}
|
||||
}
|
||||
async function logout() {
|
||||
try {
|
||||
await $fetch("/api/logout", { method: "POST" });
|
||||
} finally {
|
||||
user.value = null;
|
||||
await navigateTo("/login");
|
||||
}
|
||||
}
|
||||
return { user, ready, refresh, logout };
|
||||
});
|
||||
Reference in New Issue
Block a user