import instance from "@/util/request";
import { GET_FORGETOKEN_API, GET_FORGEURN_API } from "./api";
import apihandler from "@/util/apihandler";

export const getUrn = async () => {
  const res = await instance.post(GET_FORGEURN_API);

  return apihandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
  });
};

export const getAccessToken = async (callback) => {
  try {
    const resp = await instance.get(GET_FORGETOKEN_API);
    console.log(resp)
    const { dictionary } = resp;
    callback(dictionary.access_token, dictionary.expires_in);
  } catch (err) {
    alert("Could not obtain access token. See the console for more details.");
    console.error(err);
  }
};
