1
0
forked from noxious/client
noxious_client/src/services/authentication.ts
2024-10-21 02:15:29 +02:00

28 lines
992 B
TypeScript

import axios from 'axios'
import config from '@/config'
import { useCookies } from '@vueuse/integrations/useCookies'
export async function register(username: string, password: string) {
try {
const response = await axios.post(`${config.server_endpoint}/register`, { username, password })
useCookies().set('token', response.data.token as string)
return { success: true, token: response.data.token }
} catch (error: any) {
return { error: error.response.data.message }
}
}
export async function login(username: string, password: string) {
try {
const response = await axios.post(`${config.server_endpoint}/login`, { username, password })
useCookies().set('token', response.data.token as string, {
// for whole domain
// @TODO : #190
domain: window.location.hostname.split('.').slice(-2).join('.')
})
return { success: true, token: response.data.token }
} catch (error: any) {
return { error: error.response.data.message }
}
}