diff --git a/webui2/src/lib/auth.tsx b/webui2/src/lib/auth.tsx index 8320453c171d4d7c5a1b2a335dfc45968ca2de11..239c3e71e626d9cdc61018b91156aa5b0c0727e4 100644 --- a/webui2/src/lib/auth.tsx +++ b/webui2/src/lib/auth.tsx @@ -1,11 +1,10 @@ -// auth.tsx — authentication context for the webui. +// auth.tsx — current user hook for the webui. // -// Currently only supports local (single-user) mode: the identity is taken from -// git config at server startup and fetched via GraphQL. +// Fetches the user identity from git config via GraphQL. Apollo handles +// deduplication and caching, so no Provider/Context is needed. import { gql } from "@apollo/client"; import { useQuery } from "@apollo/client/react"; -import { createContext, useContext, type ReactNode } from "react"; const USER_IDENTITY_QUERY = gql` query UserIdentity { @@ -33,29 +32,9 @@ export interface AuthUser { login: string | null; } -export interface AuthContextValue { - user: AuthUser | null; - loading: boolean; -} - -const AuthContext = createContext({ - user: null, - loading: true, -}); - -export function AuthProvider({ children }: { children: ReactNode }) { +export function useAuth(): { user: AuthUser | null; loading: boolean } { const { data, loading } = useQuery<{ repository: { userIdentity: AuthUser | null } }>( USER_IDENTITY_QUERY, ); - const user: AuthUser | null = data?.repository?.userIdentity ?? null; - - return ( - - {children} - - ); -} - -export function useAuth(): AuthContextValue { - return useContext(AuthContext); + return { user: data?.repository?.userIdentity ?? null, loading }; } diff --git a/webui2/src/main.tsx b/webui2/src/main.tsx index 3fb0e84cea6bf9f2235269d22f61c2cebf6380ff..0271b599709d3d1ae057304e162f6030919d8a2c 100644 --- a/webui2/src/main.tsx +++ b/webui2/src/main.tsx @@ -5,7 +5,6 @@ import { createRoot } from "react-dom/client"; // eslint-disable-next-line import/no-unassigned-import import "./index.css"; import { client } from "@/lib/apollo"; -import { AuthProvider } from "@/lib/auth"; import { ThemeProvider } from "@/lib/theme"; import { App } from "./App"; @@ -14,9 +13,7 @@ createRoot(document.getElementById("root")!).render( - - - + ,