import Cookies from 'js-cookie'
import axios, { axiosErrorToast } from '../config/axios'
import { isDevelopment, isSetup } from '../constants'

export default function logout() {
  axios({
    method: 'POST',
    baseURL: process.env.REACT_APP_API_HOST,
    url: '/auth-server/auth/logout',
  })
    .then((res) => {
      if (isDevelopment || isSetup) {
        Cookies.remove('campx_tenant')
        Cookies.remove('campx_session_key')
        window.location.href = window.location.origin
      } else {
        window.location.href = 'https://id.campx.in'
      }
    })
    .catch((err) => {
      axiosErrorToast('Unable To Logout.')
    })
}
