/* Xeslint-disable */
import apiUtil from "./apiutil";
import { processLogin, processLogout } from "../utils/authutil";

export default {
  async authenticate(login, password) {
    return fetch(
      apiUtil.APIUrl("auth"),
      apiUtil.fetchPostNoAuthOptions({
        login: login,
        password: password
      })
    )
      .then(apiUtil.status)
      .then(apiUtil.json)
      .then(processLogin)
      .then(() => {
        return Promise.resolve(true);
      }) //succeeded, nothing to return
      .catch(function(error) {
        processLogout();
        return Promise.reject(error);
      });
  },
  logout() {
    processLogout();
  }
};
