zzz / frontend /src /hooks /query /use-github-user.ts
ar08's picture
Upload 1040 files
246d201 verified
raw
history blame contribute delete
936 Bytes
import { useQuery } from "@tanstack/react-query";
import React from "react";
import posthog from "posthog-js";
import { useAuth } from "#/context/auth-context";
import { useConfig } from "./use-config";
import OpenHands from "#/api/open-hands";
export const useGitHubUser = () => {
const { gitHubToken, setUserId } = useAuth();
const { data: config } = useConfig();
const user = useQuery({
queryKey: ["user", gitHubToken],
queryFn: OpenHands.getGitHubUser,
enabled: !!gitHubToken && !!config?.APP_MODE,
retry: false,
});
React.useEffect(() => {
if (user.data) {
setUserId(user.data.id.toString());
posthog.identify(user.data.login, {
company: user.data.company,
name: user.data.name,
email: user.data.email,
user: user.data.login,
mode: config?.APP_MODE || "oss",
});
}
}, [user.data]);
return user;
};