import axios from "axios";
import GetCSRF from "./GetCSRF";

const FRONT_BASE_URL = "https://app.axicon.ir/"
const BACK_BASE_URL = "https://api.axicon.ir/"

const axiosParams = {
    withCredentials: true,
    baseURL: BACK_BASE_URL,
    headers: {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': FRONT_BASE_URL,
    }
}
axios.defaults.withXSRFToken = true

const axiosInstance = axios.create(axiosParams);

export default async function LoginApi(email, password) {

    await GetCSRF()
    return (
        axiosInstance.post("login",
            {
                email: email,
                password: password
            }
        ).then((response) => {
            return response
        }).catch((error) => {
            return error.response;
        })
    )
}