Skip to content

Commit

Permalink
Add x509
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed May 29, 2024
1 parent fe304a3 commit b9c1ba6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import styles from "./app.module.scss";

export function App() {
const {
fortifyClient,
fetching,
challenge,
providers,
Expand Down Expand Up @@ -45,6 +46,7 @@ export function App() {
} = useCertificateCreateDialog({
providers,
currentProviderId,
fortifyClient,
});

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useRef } from "react";
import { IProviderInfo } from "@peculiar/fortify-client-core";
import {
IProviderInfo,
FortifyAPI,
EHashAlgorithm,
ESignatureAlgorithm,
} from "@peculiar/fortify-client-core";
import { useToast } from "@peculiar/react-components";
import { useTranslation } from "react-i18next";
import { useLockBodyScroll } from "react-use";
Expand All @@ -13,8 +18,9 @@ import { CertificateType } from "../../types";
export function useCertificateCreateDialog(props: {
providers: IProviderInfo[];
currentProviderId?: string;
fortifyClient: FortifyAPI | null;
}) {
const { providers, currentProviderId } = props;
const { providers, currentProviderId, fortifyClient } = props;
const { addToast } = useToast();
const { t } = useTranslation();

Expand All @@ -25,7 +31,7 @@ export function useCertificateCreateDialog(props: {

const dialogType = useRef<CertificateType>("x509");

const handleCertificateCreate = (data: CertificateCreateDataProps) => {
const handleCertificateCreate = async (data: CertificateCreateDataProps) => {
// Check provider
if (!localCurrentProviderId?.current) {
localCurrentProviderId.current = currentProviderId;
Expand All @@ -35,17 +41,46 @@ export function useCertificateCreateDialog(props: {
console.log("localCurrentProviderId", localCurrentProviderId.current);
const subject = certificateSubjectToString(data.subject);
console.log("subject => ", subject);
// temporary behaviour
const { type, algorithm } = data;
setIsLoading(true);
setTimeout(function () {
setIsLoading(false);
try {
if (type === "x509") {
const newCert = await fortifyClient?.createX509(
localCurrentProviderId.current as string,
{
subjectName: subject,
hashAlgorithm: algorithm?.hash as EHashAlgorithm,
signatureAlgorithm: algorithm?.signature as ESignatureAlgorithm,
}
);
if (newCert) {
console.log("newCert => ", newCert);

setIsOpen(false);
addToast({
message: t("certificates.dialog.create.success-message"),
variant: "success",
disableIcon: true,
isClosable: true,
});
} else {
addToast({
message: t("certificates.dialog.create.failure-message"),
variant: "wrong",
disableIcon: true,
isClosable: true,
});
}
}
} catch (error) {
addToast({
message: t("certificates.dialog.create.failure-message"),
variant: "wrong",
disableIcon: true,
isClosable: true,
});
}, 1000);
}
setIsLoading(false);
};

useLockBodyScroll(isOpen);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/app/useApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export function useApp() {
};

return {
fortifyClient: fortifyClient.current,
fetching,
challenge,
providers,
Expand Down

0 comments on commit b9c1ba6

Please sign in to comment.