llama-stack-mirror/llama_stack/ui/hooks/use-auth-client.ts
Antony Sallas 3059423cd7 updated to include telemetry
rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
2025-10-23 18:42:02 +08:00

28 lines
708 B
TypeScript

import { useSession } from "next-auth/react";
import { useMemo } from "react";
import LlamaStackClient from "llama-stack-client";
export function useAuthClient() {
const { data: session } = useSession();
const client = useMemo(() => {
const clientHostname =
typeof window !== "undefined" ? window.location.origin : "";
const options: any = {
baseURL: `${clientHostname}/api`,
defaultHeaders: {
"X-Telemetry-Service": "llama-stack-ui",
"X-Telemetry-Version": "1.0.0",
},
};
if (session?.accessToken) {
options.apiKey = session.accessToken;
}
return new LlamaStackClient(options);
}, [session?.accessToken]);
return client;
}