Path: blob/main/components/dashboard/src/data/auth-providers/create-org-auth-provider-mutation.ts
2501 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useMutation, useQueryClient } from "@tanstack/react-query";7import { getOrgAuthProvidersQueryKey } from "./org-auth-providers-query";8import { CreateAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";9import { authProviderClient } from "../../service/public-api";1011type CreateAuthProviderArgs = {12provider: Pick<CreateAuthProviderRequest, "host" | "type"> & {13clientId: string;14clientSecret: string;15orgId: string;16authorizationUrl?: string;17tokenUrl?: string;18};19};20export const useCreateOrgAuthProviderMutation = () => {21const queryClient = useQueryClient();2223return useMutation({24mutationFn: async ({ provider }: CreateAuthProviderArgs) => {25const response = await authProviderClient.createAuthProvider(26new CreateAuthProviderRequest({27owner: { case: "organizationId", value: provider.orgId },28host: provider.host,29oauth2Config: {30clientId: provider.clientId,31clientSecret: provider.clientSecret,32authorizationUrl: provider.authorizationUrl,33tokenUrl: provider.tokenUrl,34},35type: provider.type,36}),37);38return response.authProvider!;39},40onSuccess(provider) {41const orgId = provider?.owner?.value;42if (!orgId) {43return;44}4546queryClient.invalidateQueries({ queryKey: getOrgAuthProvidersQueryKey(orgId) });47},48});49};505152