Worked on creating new characters

This commit is contained in:
2024-05-28 23:46:55 +02:00
parent da728a1fc6
commit 8cd0e9254a
9 changed files with 70 additions and 24 deletions

View File

@ -0,0 +1,32 @@
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;
}
}