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/auth-provider-descriptions-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 } from "@tanstack/react-query";
8
import { authProviderClient } from "../../service/public-api";
9
import { useCurrentUser } from "../../user-context";
10
import {
11
AuthProviderDescription,
12
ListAuthProviderDescriptionsRequest,
13
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
14
15
export const useAuthProviderDescriptions = () => {
16
const user = useCurrentUser();
17
const query = useQuery<AuthProviderDescription[]>({
18
queryKey: getAuthProviderDescriptionsQueryKey(user?.id),
19
queryFn: async () => {
20
const params = new ListAuthProviderDescriptionsRequest();
21
if (user) {
22
params.id = {
23
case: "userId",
24
value: user.id,
25
};
26
}
27
const response = await authProviderClient.listAuthProviderDescriptions(params);
28
return response.descriptions;
29
},
30
});
31
return query;
32
};
33
34
export const getAuthProviderDescriptionsQueryKey = (userId?: string) => ["auth-provider-descriptions", { userId }];
35
36