1
0
forked from noxious/client

haha keyboard go brrr

This commit is contained in:
2024-05-16 00:26:25 +02:00
parent 2638d6024f
commit 1ed0283a94
8 changed files with 154 additions and 153 deletions

View File

@ -0,0 +1,32 @@
import axios from 'axios';
import config from '@/config';
import { useSocketStore } from '@/stores/socket';
export async function register(username: string, password: string, socketStore = useSocketStore()) {
if (socketStore.getAuthenticated) return console.log('User already authenticated');
try {
const response = await axios.post(`${config.server_endpoint}/register`, { username, password });
console.log(response.data);
return true;
} catch (error) {
console.error('Error registering user:', error);
return false;
}
}
export async function login(username: string, password: string, socketStore = useSocketStore()) {
if (socketStore.getAuthenticated) return console.log('User already authenticated');
try {
const response = await axios.post(`${config.server_endpoint}/login`, { username, password });
if (response.status === 200) {
socketStore.isAuthenticated = true;
socketStore.setupSocketConnection(username, password);
return true;
}
} catch (error) {
console.error('Login failed:', error);
return false;
}
}