diff --git a/src/components/AiChatWidget.tsx b/src/components/AiChatWidget.tsx index 5aacfc7..7f039a3 100644 --- a/src/components/AiChatWidget.tsx +++ b/src/components/AiChatWidget.tsx @@ -1,7 +1,7 @@ import { createSignal, Show, For, onMount } from "solid-js"; import { MessageCircle, X, Send, Bot, User, Loader } from "lucide-solid"; -const API = "/api/gateway"; +const API = "/api"; interface ChatMessage { role: "user" | "assistant"; @@ -62,12 +62,18 @@ export function AiChatWidget() { const [usage, setUsage] = createSignal(null); onMount(() => { - fetchUsage(); + const hasToken = typeof window !== "undefined" && !!sessionStorage.getItem("nxtgauge_access_token"); + if (hasToken) fetchUsage(); }); const fetchUsage = async () => { try { - const res = await fetch(`${API}/api/ai/usage/summary`); + const res = await fetch(`${API}/ai/usage/summary`, { + headers: { + Authorization: `Bearer ${sessionStorage.getItem("nxtgauge_access_token") || ""}`, + }, + credentials: "include", + }); if (!res.ok) return; const data = await res.json(); const plan = data.plan_details || data.plan || {}; @@ -97,7 +103,7 @@ export function AiChatWidget() { setInput(""); try { - let res = await fetch(`${API}/api/ai/chat/ask`, { + let res = await fetch(`${API}/ai/chat/ask`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -107,7 +113,7 @@ export function AiChatWidget() { }); if (res.status === 401 || res.status === 403 || res.status === 404) { - res = await fetch(`${API}/api/ai/chat/message`, { + res = await fetch(`${API}/ai/chat/message`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -189,6 +195,8 @@ export function AiChatWidget() { transition: "transform 0.2s", }} title="AI Assistant" + aria-label={isOpen() ? "Close AI Assistant" : "Open AI Assistant"} + aria-expanded={isOpen()} > }> diff --git a/src/components/dashboard/CompanyJobsPage.tsx b/src/components/dashboard/CompanyJobsPage.tsx index f2def9f..4493498 100644 --- a/src/components/dashboard/CompanyJobsPage.tsx +++ b/src/components/dashboard/CompanyJobsPage.tsx @@ -165,7 +165,10 @@ export default function CompanyJobsPage() { const loadAiUsage = async () => { const token = window.sessionStorage.getItem("nxtgauge_access_token") || ""; - const res = await fetch(`${API}/api/ai/usage/summary`, { + // Gateway resolve_upstream() only matches paths starting with "/api/ai" - + // there is no "/api/gateway" rewrite in production, so this must not add + // one, and API already is "/api" so it must not repeat that prefix either. + const res = await fetch(`${API}/ai/usage/summary`, { headers: { Authorization: `Bearer ${token}` }, }); if (res.ok) {