import { defineStore } from "pinia"; import { ref } from "vue"; import { repo } from "../adapters"; // A linked native client (Tauri/Android) that holds a device bearer token. export interface Device { id: string; name: string; created_at: string | null; last_used_at: string | null; } export const useDevicesStore = defineStore("devices", () => { const items = ref([]); const loading = ref(false); async function load(): Promise { loading.value = true; try { items.value = await repo.devices.list(); } finally { loading.value = false; } } // Issues a token for the current user; the plaintext token is returned ONCE // (never retrievable again) for the caller to display + copy. async function create(name: string): Promise { const res = await repo.devices.create(name); items.value.unshift(res.device); return res.token; } async function revoke(id: string): Promise { await repo.devices.remove(id); items.value = items.value.filter((d) => d.id !== id); } return { items, loading, load, create, revoke }; });