mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-14 09:06:10 +00:00
# What does this PR do? Uses NextAuth to add github sign in support. ## Test Plan Start server with auth configured as in https://github.com/meta-llama/llama-stack/pull/2509 https://github.com/user-attachments/assets/61ff7442-f601-4b39-8686-5d0afb3b45ac
24 lines
586 B
TypeScript
24 lines
586 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`,
|
|
};
|
|
|
|
if (session?.accessToken) {
|
|
options.apiKey = session.accessToken;
|
|
}
|
|
|
|
return new LlamaStackClient(options);
|
|
}, [session?.accessToken]);
|
|
|
|
return client;
|
|
}
|