Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/auth-providers/org-auth-providers-query.ts
2501 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useQuery, useQueryClient } from "@tanstack/react-query";
8
import { useCallback } from "react";
9
import { useCurrentOrg } from "../organizations/orgs-query";
10
import { authProviderClient } from "../../service/public-api";
11
import { AuthProvider, ListAuthProvidersRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
12
13
export const useOrgAuthProvidersQuery = () => {
14
const organization = useCurrentOrg().data;
15
16
return useQuery<AuthProvider[]>({
17
queryKey: getOrgAuthProvidersQueryKey(organization?.id ?? ""),
18
queryFn: async () => {
19
if (!organization) {
20
throw new Error("No current organization selected");
21
}
22
23
const response = await authProviderClient.listAuthProviders(
24
new ListAuthProvidersRequest({
25
id: {
26
case: "organizationId",
27
value: organization.id,
28
},
29
}),
30
);
31
32
return response.authProviders;
33
},
34
});
35
};
36
37
export const useInvalidateOrgAuthProvidersQuery = (organizationId: string) => {
38
const queryClient = useQueryClient();
39
40
return useCallback(() => {
41
queryClient.invalidateQueries({ queryKey: getOrgAuthProvidersQueryKey(organizationId) });
42
}, [organizationId, queryClient]);
43
};
44
45
export const getOrgAuthProvidersQueryKey = (organizationId: string) => ["org-auth-providers", { organizationId }];
46
47