AkurAI Build
Menu

popagent

public

Latest change 6edc7e928c57dab23c0973ed3f7ee70b3ebb72d5 - Initial popagent baseline by AkurAI Build

export async function apiFetch(input: RequestInfo | URL, init: RequestInit = {}): Promise<Response> {
  const key = typeof localStorage !== "undefined" ? localStorage.getItem("popagent:api-key") : null;
  const headers = new Headers(init.headers);
  if (key) headers.set("x-popagent-key", key);
  const response = await fetch(input, { ...init, headers });
  if (response.status === 401 && typeof window !== "undefined") window.dispatchEvent(new CustomEvent("popagent:unauthorized"));
  return response;
}