import axios from "axios";
import Cookies from "js-cookie";
import { apiURL, appURL } from "./const";

export const authCall = async (path: string, cb: any) => {
  await axios
    .post(`${apiURL}/auth/${path}`)
    .then((response) => {
      cb(response.data);
    })
    .catch(function (error) {
      console.log(error);
    });
};

export const apiCall = async (path: string, options: any, cb: any) => {
  
  await axios
    .post(`${apiURL}/${path}`,
      options,
      {
      headers: {
        "Content-type": "Application/json",
        Authorization: "Bearer " + Cookies.get("idToken"),
      },
    })
    .then((response) => {
      if(response.data.error){
        console.log(response)
        // window.location.href = `${appURL}server-error`
      } else{
        cb(response.data);
      }
    })
    .catch(function (error) {
      console.log(error);
    });
};



