refactor(web): drop AuthProvider, use Apollo cache directly
Quentin Gliech
and
Claude Opus 4.6 (1M context)
created 1 month ago
The useAuth hook now just wraps a useQuery call. Apollo deduplicates and
caches the result, so a dedicated React context is unnecessary.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Change summary
webui2/src/lib/auth.tsx | 31 +++++--------------------------
webui2/src/main.tsx | 5 +----
2 files changed, 6 insertions(+), 30 deletions(-)
Detailed changes
@@ -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<AuthContextValue>({
- 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 (
- <AuthContext.Provider value={{ user, loading }}>
- {children}
- </AuthContext.Provider>
- );
-}
-
-export function useAuth(): AuthContextValue {
- return useContext(AuthContext);
+ return { user: data?.repository?.userIdentity ?? null, loading };
}
@@ -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(
<StrictMode>
<ThemeProvider>
<ApolloProvider client={client}>
- <AuthProvider>
- <App />
- </AuthProvider>
+ <App />
</ApolloProvider>
</ThemeProvider>
</StrictMode>,