import axios from "axios";
import { userInfoStore } from "@/store/store";

const userinfo = userInfoStore();

export const getUserInfo = async () => {
  console.log("getUserInfojs was used!");
  try {
    const response = await axios.get("/api/blog/get/userinfo", {
      headers: {
        Authorization: "Bearer " + userinfo.token,
      },
    });
    if (response.data.code === 200) {
      userinfo.user.u_id = response.data.data.u_id;
      userinfo.user.u_name = response.data.data.u_name;
      userinfo.user.u_avatar = response.data.data.u_avatar;
      userinfo.user.role = response.data.data.role;
      console.log(userinfo.user);
    }
  } catch (error) {
    console.log(error);
  }
};
