Path: blob/main/components/dashboard/src/teams/sso/use-verify-client.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 { useCallback } from "react";7import { openOIDCStartWindow } from "../../provider-utils";8import { useInvalidateOIDCClientsQuery } from "../../data/oidc-clients/oidc-clients-query";910type Props = {11onSuccess: (configId: string) => void;12onError: (errorMessage: string) => void;13};14export const useVerifyClient = ({ onSuccess, onError }: Props) => {15const invalidateClients = useInvalidateOIDCClientsQuery();1617return useCallback(18async (configId: string) => {19await openOIDCStartWindow({20verify: true,21configId,22// TODO: fix callback to not call for previous windows23onSuccess: async () => {24invalidateClients();25onSuccess(configId);26},27onError: (payload) => {28let errorMessage: string;29if (typeof payload === "string") {30errorMessage = payload;31} else {32errorMessage = payload.description ? payload.description : `Error: ${payload.error}`;33}3435onError(errorMessage);36},37});38},39[invalidateClients, onError, onSuccess],40);41};424344