Removed in page callback (#6657)

This commit is contained in:
tofarr 2025-02-10 12:34:58 +00:00 committed by GitHub
parent 61c709b7c7
commit 707cb07f4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 52 deletions

View File

@ -132,6 +132,7 @@ describe("AccountSettingsModal", () => {
agent: "CodeActAgent",
confirmation_mode: false,
enable_default_condenser: false,
github_token: undefined,
language: "en",
llm_base_url: "",
llm_model: "anthropic/claude-3-5-sonnet-20241022",

View File

@ -5,10 +5,16 @@ interface AuthContextType {
setGitHubTokenIsSet: (value: boolean) => void;
}
interface AuthContextProps extends React.PropsWithChildren {
initialGithubTokenIsSet?: boolean;
}
const AuthContext = React.createContext<AuthContextType | undefined>(undefined);
function AuthProvider({ children }: React.PropsWithChildren) {
const [githubTokenIsSet, setGitHubTokenIsSet] = React.useState(false);
function AuthProvider({ children, initialGithubTokenIsSet }: AuthContextProps) {
const [githubTokenIsSet, setGitHubTokenIsSet] = React.useState(
!!initialGithubTokenIsSet,
);
const value = React.useMemo(
() => ({

View File

@ -50,13 +50,5 @@ export const useSettings = () => {
setGitHubTokenIsSet(!!query.data?.GITHUB_TOKEN_IS_SET);
}, [query.data?.GITHUB_TOKEN_IS_SET, query.isFetched]);
// Return default settings if in SAAS mode and not authenticated
if (config?.APP_MODE === "saas" && !githubTokenIsSet) {
return {
...query,
data: DEFAULT_SETTINGS,
};
}
return query;
};

View File

@ -15,6 +15,4 @@ export default [
route("served", "routes/app.tsx"),
]),
]),
route("oauth/github/callback", "routes/oauth.github.callback.tsx"),
] satisfies RouteConfig;

View File

@ -1,39 +0,0 @@
import { useNavigate, useSearchParams } from "react-router";
import { useQuery } from "@tanstack/react-query";
import React from "react";
import OpenHands from "#/api/open-hands";
function OAuthGitHubCallback() {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const code = searchParams.get("code");
const { isSuccess, error } = useQuery({
queryKey: ["access_token", code],
queryFn: () => OpenHands.getGitHubAccessToken(code!),
enabled: !!code,
});
React.useEffect(() => {
if (isSuccess) {
navigate("/");
}
}, [isSuccess]);
if (error) {
return (
<div>
<h1>Error</h1>
<p>{error.message}</p>
</div>
);
}
return (
<div>
<h1>Redirecting...</h1>
</div>
);
}
export default OAuthGitHubCallback;

View File

@ -66,7 +66,7 @@ export function renderWithProviders(
function Wrapper({ children }: PropsWithChildren) {
return (
<Provider store={store}>
<AuthProvider>
<AuthProvider initialGithubTokenIsSet={true}>
<QueryClientProvider
client={
new QueryClient({