Skip to content

Commit

Permalink
Better logout
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape committed Jan 27, 2025
1 parent 64fde99 commit 6d6cce7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions frontend/src/hooks/query/use-github-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { useConfig } from "./use-config";
import OpenHands from "#/api/open-hands";
import { useAuth } from "#/context/auth-context";
import { useLogout } from "../mutation/use-logout";
import { useCurrentSettings } from "#/context/settings-context";

export const useGitHubUser = () => {
const { githubTokenIsSet } = useAuth();
const { mutate: logout } = useLogout();
const { setGitHubTokenIsSet } = useAuth();
const { mutateAsync: logout } = useLogout();
const { saveUserSettings } = useCurrentSettings();
const { data: config } = useConfig();

const user = useQuery({
Expand All @@ -30,9 +33,18 @@ export const useGitHubUser = () => {
}
}, [user.data]);

const handleLogout = async () => {
if (config?.APP_MODE === "saas") await logout();
else {
await saveUserSettings({ unset_github_token: true });
setGitHubTokenIsSet(false);
}
posthog.reset();
};

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

Expand Down

0 comments on commit 6d6cce7

Please sign in to comment.