mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
24 lines
770 B
TypeScript
24 lines
770 B
TypeScript
import React from "react";
|
|
import { generateGitHubAuthUrl } from "#/utils/generate-github-auth-url";
|
|
import { GetConfigResponse } from "#/api/open-hands.types";
|
|
import { useAuth } from "#/context/auth-context";
|
|
|
|
interface UseGitHubAuthUrlConfig {
|
|
appMode: GetConfigResponse["APP_MODE"] | null;
|
|
gitHubClientId: GetConfigResponse["GITHUB_CLIENT_ID"] | null;
|
|
}
|
|
|
|
export const useGitHubAuthUrl = (config: UseGitHubAuthUrlConfig) => {
|
|
const { githubTokenIsSet } = useAuth();
|
|
|
|
return React.useMemo(() => {
|
|
if (config.appMode === "saas" && !githubTokenIsSet)
|
|
return generateGitHubAuthUrl(
|
|
config.gitHubClientId || "",
|
|
new URL(window.location.href),
|
|
);
|
|
|
|
return null;
|
|
}, [githubTokenIsSet, config.appMode, config.gitHubClientId]);
|
|
};
|