Skip to content

Commit

Permalink
hotfix(frontend): Logout and clear token if retrieving user fails (#6436
Browse files Browse the repository at this point in the history
)
  • Loading branch information
amanape authored Jan 24, 2025
1 parent e6a2fd3 commit 358d9cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/hooks/query/use-github-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -29,5 +29,11 @@ export const useGitHubUser = () => {
}
}, [user.data]);

React.useEffect(() => {
if (user.isError) {
logout();
}
}, [user.isError]);

return user;
};
2 changes: 1 addition & 1 deletion frontend/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 358d9cb

Please sign in to comment.