Spaces:
Configuration error

File size: 912 Bytes
2d63f96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { useMutation, useQueryClient } from "@tanstack/react-query";
import OpenHands from "#/api/open-hands";
import { useAuth } from "#/context/auth-context";
import { useConfig } from "../query/use-config";

export const useLogout = () => {
  const { setGitHubTokenIsSet } = useAuth();
  const queryClient = useQueryClient();
  const { data: config } = useConfig();

  return useMutation({
    mutationFn: async () => {
      // Pause all queries that depend on githubTokenIsSet
      queryClient.setQueryData(["user"], null);

      // Call logout endpoint
      await OpenHands.logout(config?.APP_MODE ?? "oss");

      // Remove settings from cache so it will be refetched with new token state
      queryClient.removeQueries({ queryKey: ["settings"] });

      // Update token state - this will trigger a settings refetch since it's part of the query key
      setGitHubTokenIsSet(false);
    },
  });
};