import { defineStore } from 'pinia' import { ref, computed } from 'vue' import { login as apiLogin } from '../api/auth' const TOKEN_KEY = 'auth_token' export const useAuthStore = defineStore('auth', () => { const token = ref(localStorage.getItem(TOKEN_KEY)) const isLoggedIn = computed(() => token.value !== null) async function login(username: string, password: string) { const resp = await apiLogin(username, password) token.value = resp.token localStorage.setItem(TOKEN_KEY, resp.token) } function logout() { token.value = null localStorage.removeItem(TOKEN_KEY) } return { token, isLoggedIn, login, logout } })