import { ref } from "vue"; import { defineStore } from "pinia"; import type { User } from "@/types"; export const useAuthStore = defineStore("auth", () => { const isAuthenticated = ref(false); const user = ref(null); async function getUser() { try { const response = await fetch("/api/me"); const data = await response.json(); user.value = data.profile; isAuthenticated.value = true; } catch {} } async function waitForAuth() { while (!isAuthenticated.value) { await getUser(); } } return { isAuthenticated, user, getUser, waitForAuth, }; });