From 224368b172c704592861fa26d60af6e3cc7b882f Mon Sep 17 00:00:00 2001 From: Alfonso Hernandez Date: Fri, 19 Jul 2024 12:20:46 +0200 Subject: [PATCH] fix: general access accessible only from private creation --- .../server/routes/v1/secret-sharing-router.ts | 7 +- .../components/AddShareSecretForm.tsx | 67 +++++++++++-------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/backend/src/server/routes/v1/secret-sharing-router.ts b/backend/src/server/routes/v1/secret-sharing-router.ts index 9e5fe1f79..d5c6a9884 100644 --- a/backend/src/server/routes/v1/secret-sharing-router.ts +++ b/backend/src/server/routes/v1/secret-sharing-router.ts @@ -95,8 +95,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) => tag: z.string(), hashedHex: z.string(), expiresAt: z.string(), - expiresAfterViews: z.number(), - accessType: z.nativeEnum(SecretSharingAccessType).default(SecretSharingAccessType.Organization) + expiresAfterViews: z.number() }), response: { 200: z.object({ @@ -105,7 +104,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) => } }, handler: async (req) => { - const { encryptedValue, iv, tag, hashedHex, expiresAt, expiresAfterViews, accessType } = req.body; + const { encryptedValue, iv, tag, hashedHex, expiresAt, expiresAfterViews } = req.body; const sharedSecret = await req.server.services.secretSharing.createPublicSharedSecret({ encryptedValue, iv, @@ -113,7 +112,7 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) => hashedHex, expiresAt: new Date(expiresAt), expiresAfterViews, - accessType + accessType: SecretSharingAccessType.Anyone }); return { id: sharedSecret.id }; } diff --git a/frontend/src/views/ShareSecretPage/components/AddShareSecretForm.tsx b/frontend/src/views/ShareSecretPage/components/AddShareSecretForm.tsx index bbc896460..47da21693 100644 --- a/frontend/src/views/ShareSecretPage/components/AddShareSecretForm.tsx +++ b/frontend/src/views/ShareSecretPage/components/AddShareSecretForm.tsx @@ -1,5 +1,6 @@ import crypto from "crypto"; +import { useEffect, useRef } from "react"; import { Controller } from "react-hook-form"; import { AxiosError } from "axios"; import * as yup from "yup"; @@ -36,6 +37,14 @@ export const AddShareSecretForm = ({ setNewSharedSecret: (value: string) => void; isInputDisabled?: boolean; }) => { + const isMounted = useRef(true); + + useEffect(() => { + return () => { + isMounted.current = false; + }; + }, []); + const publicSharedSecretCreator = useCreatePublicSharedSecret(); const privateSharedSecretCreator = useCreateSharedSecret(); const createSharedSecret = isPublic ? publicSharedSecretCreator : privateSharedSecretCreator; @@ -94,16 +103,18 @@ export const AddShareSecretForm = ({ expiresAfterViews: expiresAfterSingleView ? 1 : 1000, accessType: accessType as SecretSharingAccessType }); - setNewSharedSecret( - `${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent( - hashedHex - )}-${encodeURIComponent(key)}` - ); - createNotification({ - text: "Successfully created a shared secret", - type: "success" - }); + if (isMounted.current) { + setNewSharedSecret( + `${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent( + hashedHex + )}-${encodeURIComponent(key)}` + ); + createNotification({ + text: "Successfully created a shared secret", + type: "success" + }); + } } catch (err) { console.error(err); const axiosError = err as AxiosError; @@ -146,7 +157,7 @@ export const AddShareSecretForm = ({ )} /> -
+
@@ -230,23 +241,25 @@ export const AddShareSecretForm = ({
- ( - - - - )} - /> -
+ {!isPublic && ( + ( + + + + )} + /> + )} +