π OpenHands: AI-Driven Development
hotfix(frontend): Logout and clear token if retrieving user fails (#6436)
sp.wack358d9cb3f4df
diff --git a/frontend/__tests__/components/features/sidebar/sidebar.test.tsx b/frontend/__tests__/components/features/sidebar/sidebar.test.tsxindex 1f2ad6c57a..dbba5c079f 100644--- a/frontend/__tests__/components/features/sidebar/sidebar.test.tsx+++ b/frontend/__tests__/components/features/sidebar/sidebar.test.tsx@@ -155,7 +155,9 @@ describe("Sidebar", () => {const settingsModal = screen.getByTestId("ai-config-modal");// Click the advanced options switch to show the API key input- const advancedOptionsSwitch = within(settingsModal).getByTestId("advanced-option-switch");+ const advancedOptionsSwitch = within(settingsModal).getByTestId(+ "advanced-option-switch",+ );await user.click(advancedOptionsSwitch);const apiKeyInput = within(settingsModal).getByLabelText(/API\$KEY/i);diff --git a/frontend/src/hooks/query/use-github-user.ts b/frontend/src/hooks/query/use-github-user.tsindex 9841f6524c..7d24e12abc 100644--- a/frontend/src/hooks/query/use-github-user.ts+++ b/frontend/src/hooks/query/use-github-user.ts@@ -6,7 +6,7 @@ import { useConfig } from "./use-config";import OpenHands from "#/api/open-hands";export const useGitHubUser = () => {- const { gitHubToken, setUserId } = useAuth();+ const { gitHubToken, setUserId, logout } = useAuth();const { data: config } = useConfig();const user = useQuery({@@ -29,5 +29,11 @@ export const useGitHubUser = () => {}}, [user.data]);+ React.useEffect(() => {+ if (user.isError) {+ logout();+ }+ }, [user.isError]);+return user;};diff --git a/frontend/src/mocks/handlers.ts b/frontend/src/mocks/handlers.tsindex 9d1a42d430..d9c40ff146 100644--- a/frontend/src/mocks/handlers.ts+++ b/frontend/src/mocks/handlers.ts@@ -141,7 +141,7 @@ export const handlers = [{ id: 2, full_name: "octocat/earth" },]),),- http.get("https://api.github.com/user", () => {+ http.get("/api/github/user", () => {const user: GitHubUser = {id: 1,login: "octocat",