Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/teams/sso/use-verify-client.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 { useCallback } from "react";
8
import { openOIDCStartWindow } from "../../provider-utils";
9
import { useInvalidateOIDCClientsQuery } from "../../data/oidc-clients/oidc-clients-query";
10
11
type Props = {
12
onSuccess: (configId: string) => void;
13
onError: (errorMessage: string) => void;
14
};
15
export const useVerifyClient = ({ onSuccess, onError }: Props) => {
16
const invalidateClients = useInvalidateOIDCClientsQuery();
17
18
return useCallback(
19
async (configId: string) => {
20
await openOIDCStartWindow({
21
verify: true,
22
configId,
23
// TODO: fix callback to not call for previous windows
24
onSuccess: async () => {
25
invalidateClients();
26
onSuccess(configId);
27
},
28
onError: (payload) => {
29
let errorMessage: string;
30
if (typeof payload === "string") {
31
errorMessage = payload;
32
} else {
33
errorMessage = payload.description ? payload.description : `Error: ${payload.error}`;
34
}
35
36
onError(errorMessage);
37
},
38
});
39
},
40
[invalidateClients, onError, onSuccess],
41
);
42
};
43
44