import ky from "ky";
import useAuthStore from "../stores/useAuthStore";

const api = ky.create({
  prefixUrl: import.meta.env.VITE_API_URL,
  retry: 0,
  hooks: {
    beforeRequest: [
      (request) => {
        const token = useAuthStore.getState().token;

        if (token) {
          request.headers.set("Authorization", `Bearer ${token}`);
        }
      },
    ],
  },
});

export default api;
