frontend/requests/login.ts

13 lines
443 B
TypeScript

import axios, { AxiosError, type AxiosResponse } from "axios";
import type { User } from "~/classes/User";
export function login(user: User, onSuccess: (token: string) => void, onError: (code?: string) => void)
{
axios.post<string>(ApiConfig.getHttpBase() + '/login', user)
.then((response) => {
onSuccess(response.data);
})
.catch((error: AxiosError<string, any>) => {
onError(error.response?.data);
});
}