import { getToken, removeToken } from "@/auth/auth";
import { httpApp } from "@/plugins/axiosApp";

/** 登录 */
export function loginByUsername(loginInfo: {
  accountValue: string;
  password: string;
  rootOrgId: number;
}) {
  return httpApp.post("/api/ess/auth/login", loginInfo, {
    noErrorMessage: true,
  });
}

/** 登出 */
export async function logout() {
  const token = getToken();
  if (token) {
    return httpApp
      .post("/api/ess/auth/logout", null, {
        "axios-retry": {
          retries: 0,
        },
      })
      .catch((e) => console.log(e))
      .finally(() => removeToken());
  } else {
    return;
  }
}
