fix: better error handling & renamed handler function

This commit is contained in:
Daniel Hougaard
2025-04-03 08:23:12 +04:00
parent c4c065ea9e
commit fda77fe464
@@ -68,13 +68,22 @@ const VerifyForm = ({ cmek }: FormProps) => {
} }
}); });
const handleSignData = async (formData: FormData) => { const handleVerifyData = async (formData: FormData) => {
try { try {
await cmekVerify.mutateAsync({ ...formData, keyId: cmek.id }); const result = await cmekVerify.mutateAsync({ ...formData, keyId: cmek.id });
createNotification({
text: "Successfully signed data", if (result.signatureValid) {
type: "success" createNotification({
}); text: "Successfully verified signature",
type: "success"
});
} else {
createNotification({
title: "Signature Verification Failed",
text: "The signature is invalid. The signature was not created using the same signing algorithm and key as the one used to sign the data. The data and signature may have been tampered with.",
type: "error"
});
}
} catch (err) { } catch (err) {
console.error(err); console.error(err);
createNotification({ createNotification({
@@ -98,7 +107,7 @@ const VerifyForm = ({ cmek }: FormProps) => {
); );
return ( return (
<form onSubmit={handleSubmit(handleSignData)}> <form onSubmit={handleSubmit(handleVerifyData)}>
{signatureValid !== undefined ? ( {signatureValid !== undefined ? (
<div className="mb-6 flex flex-col gap-2"> <div className="mb-6 flex flex-col gap-2">
<div className="flex items-center justify-between space-x-2"> <div className="flex items-center justify-between space-x-2">