feat: simplified ui for password based secret sharing

This commit is contained in:
=
2024-08-10 22:21:17 +05:30
parent a5555c3816
commit 3ddb4cd27a
7 changed files with 89 additions and 111 deletions
+15 -34
View File
@@ -7,7 +7,11 @@ import { TSharedSecret, TViewSharedSecretResponse } from "./types";
export const secretSharingKeys = {
allSharedSecrets: () => ["sharedSecrets"] as const,
specificSharedSecrets: ({ offset, limit }: { offset: number; limit: number }) =>
[...secretSharingKeys.allSharedSecrets(), { offset, limit }] as const
[...secretSharingKeys.allSharedSecrets(), { offset, limit }] as const,
getSecretById: (arg: { id: string; hashedHex: string; password?: string }) => [
"shared-secret",
arg
]
};
export const useGetSharedSecrets = ({
@@ -38,51 +42,28 @@ export const useGetSharedSecrets = ({
export const useGetActiveSharedSecretById = ({
sharedSecretId,
hashedHex
hashedHex,
password
}: {
sharedSecretId: string;
hashedHex: string;
password?: string;
}) => {
return useQuery<TViewSharedSecretResponse | null>(
[`sharedSecret-${sharedSecretId}`],
return useQuery<TViewSharedSecretResponse>(
secretSharingKeys.getSecretById({ id: sharedSecretId, hashedHex, password }),
async () => {
const params = new URLSearchParams({ hashedHex });
const { data } = await apiRequest.get<TViewSharedSecretResponse>(
const { data } = await apiRequest.post<TViewSharedSecretResponse>(
`/api/v1/secret-sharing/public/${sharedSecretId}`,
{
params
hashedHex,
password
}
);
if (!data) return null
return {
encryptedValue: data.encryptedValue,
iv: data.iv,
tag: data.tag,
accessType: data.accessType,
orgName: data.orgName
};
return data;
},
{
enabled: Boolean(sharedSecretId) && Boolean(hashedHex)
}
);
};
// returns a secret (secret or undefined if password doesn't match)
export const fetchSecretIfPasswordIsValid = async (
sharedSecretId: string,
hashedHex: string,
password: string,
) => {
const { data } = await apiRequest.post<TViewSharedSecretResponse>(
`/api/v1/secret-sharing/public/${sharedSecretId}/validate`,
{
hashedHex,
password
}
);
return data;
};
+10 -6
View File
@@ -26,11 +26,14 @@ export type TCreateSharedSecretRequest = {
};
export type TViewSharedSecretResponse = {
encryptedValue: string;
iv: string;
tag: string;
accessType: SecretSharingAccessType;
orgName?: string;
isPasswordProtected: boolean;
secret: {
encryptedValue: string;
iv: string;
tag: string;
accessType: SecretSharingAccessType;
orgName?: string;
};
};
export type TDeleteSharedSecretRequest = {
@@ -40,4 +43,5 @@ export type TDeleteSharedSecretRequest = {
export enum SecretSharingAccessType {
Anyone = "anyone",
Organization = "organization"
}
}