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