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/user-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 } from "@tanstack/react-query";
8
import { authProviderClient } from "../../service/public-api";
9
import { AuthProvider, ListAuthProvidersRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
10
import { useCurrentUser } from "../../user-context";
11
12
export type OrgAuthProvidersQueryResult = AuthProvider[];
13
export const useOrgAuthProvidersQuery = () => {
14
const user = useCurrentUser();
15
16
return useQuery<OrgAuthProvidersQueryResult>({
17
queryKey: getUserAuthProvidersQueryKey(user?.id ?? ""),
18
queryFn: async () => {
19
if (!user) {
20
throw new Error("No user");
21
}
22
23
const response = await authProviderClient.listAuthProviders(
24
new ListAuthProvidersRequest({
25
id: {
26
case: "userId",
27
value: user.id,
28
},
29
}),
30
);
31
32
return response.authProviders;
33
},
34
enabled: !!user,
35
});
36
};
37
38
export const getUserAuthProvidersQueryKey = (userId: string) => ["user-auth-providers", { userId }];
39
40