MCPcopy
hub / github.com/OpenHands/OpenHands / useGitUser

Function useGitUser

frontend/src/hooks/query/use-git-user.ts:9–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import { useLogout } from "../mutation/use-logout";
8
9export const useGitUser = () => {
10 const posthog = usePostHog();
11 const { data: config } = useConfig();
12 const logout = useLogout();
13
14 // Use the Git-specific hook to determine if we should fetch user data.
15 // This requires a Git provider to be configured, not just authentication.
16 const shouldFetchUser = useShouldShowGitFeatures();
17
18 const user = useQuery({
19 queryKey: ["user"],
20 queryFn: UserService.getUser,
21 enabled: shouldFetchUser,
22 retry: false,
23 staleTime: 1000 * 60 * 5, // 5 minutes
24 gcTime: 1000 * 60 * 15, // 15 minutes
25 });
26
27 React.useEffect(() => {
28 if (user.data) {
29 posthog.identify(user.data.login, {
30 company: user.data.company,
31 name: user.data.name,
32 email: user.data.email,
33 user: user.data.login,
34 mode: config?.app_mode || "oss",
35 });
36 }
37 }, [user.data]);
38
39 // In saas mode, a 401 means that the integration tokens need to be
40 // refreshed. Since this happens at login, we log out.
41 // In oss mode, skip auto-logout since there's no token refresh mechanism
42 React.useEffect(() => {
43 if (user?.error?.response?.status === 401 && config?.app_mode === "saas") {
44 logout.mutate();
45 }
46 }, [user.status, config?.app_mode]);
47
48 return user;
49};

Callers 3

SidebarFunction · 0.90
useReoTrackingFunction · 0.90

Calls 4

useConfigFunction · 0.90
useLogoutFunction · 0.90
useShouldShowGitFeaturesFunction · 0.90
identifyMethod · 0.80

Tested by

no test coverage detected