forked from noxious/client
npm run format
This commit is contained in:
@ -1,32 +1,32 @@
|
||||
import axios from 'axios';
|
||||
import config from '@/config';
|
||||
import { useSocketStore } from '@/stores/socket';
|
||||
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 });
|
||||
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;
|
||||
await socketStore.setupSocketConnection()
|
||||
return true
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error registering user:', error);
|
||||
return false;
|
||||
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 });
|
||||
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;
|
||||
await socketStore.setupSocketConnection()
|
||||
return true
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error);
|
||||
return false;
|
||||
console.error('Login failed:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user