Path: blob/main/components/dashboard/src/data/auth-providers/create-user-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 { CreateAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";8import { authProviderClient } from "../../service/public-api";9import { getUserAuthProvidersQueryKey } from "./user-auth-providers-query";1011type CreateAuthProviderArgs = {12provider: Pick<CreateAuthProviderRequest, "host" | "type"> & {13clientId: string;14clientSecret: string;15userId: string;16authorizationUrl?: string;17tokenUrl?: string;18};19};20export const useCreateUserAuthProviderMutation = () => {21const queryClient = useQueryClient();2223return useMutation({24mutationFn: async ({ provider }: CreateAuthProviderArgs) => {25const response = await authProviderClient.createAuthProvider(26new CreateAuthProviderRequest({27owner: { case: "ownerId", value: provider.userId },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 userId = provider?.owner?.value;42if (!userId) {43return;44}4546queryClient.invalidateQueries({ queryKey: getUserAuthProvidersQueryKey(userId) });47},48});49};505152