import axios from 'axios' import config from '@/config' import { useSocketStore } from '@/stores/socket' import { useCookies } from '@vueuse/integrations/useCookies' export async function register(username: string, password: string, socketStore = useSocketStore()) { try { const response = await axios.post(`${config.server_endpoint}/register`, { username, password }) if (response.status === 200) { useCookies().set('token', response.data.token as string) await socketStore.setupSocketConnection() return true } } catch (error) { console.error('Error registering user:', error) return false } } export async function login(username: string, password: string, socketStore = useSocketStore()) { try { const response = await axios.post(`${config.server_endpoint}/login`, { username, password }) if (response.status === 200) { useCookies().set('token', response.data.token as string) await socketStore.setupSocketConnection() return true } } catch (error) { console.error('Login failed:', error) return false } }