mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix(lint): fix type errors
This commit is contained in:
@@ -21,6 +21,7 @@ export const SecretSharingSchema = z.object({
|
|||||||
expiresAfterViews: z.number().nullable().optional(),
|
expiresAfterViews: z.number().nullable().optional(),
|
||||||
accessType: z.string().default("anyone"),
|
accessType: z.string().default("anyone"),
|
||||||
name: z.string().nullable().optional(),
|
name: z.string().nullable().optional(),
|
||||||
|
password: z.string().nullable().optional(),
|
||||||
lastViewedAt: z.date().nullable().optional()
|
lastViewedAt: z.date().nullable().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ export const registerSecretSharingRouter = async (server: FastifyZodProvider) =>
|
|||||||
orgId: req.permission?.orgId
|
orgId: req.permission?.orgId
|
||||||
});
|
});
|
||||||
|
|
||||||
// return undefined if it does not exist, has password set or has no more views allowed.
|
|
||||||
if (!sharedSecret || sharedSecret.password) return undefined;
|
if (!sharedSecret || sharedSecret.password) return undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, InternalServerError, NotFoundError, UnauthorizedError } from "@app/lib/errors";
|
||||||
import { SecretSharingAccessType } from "@app/lib/types";
|
import { SecretSharingAccessType } from "@app/lib/types";
|
||||||
|
|
||||||
import { TOrgDALFactory } from "../org/org-dal";
|
import { TOrgDALFactory } from "../org/org-dal";
|
||||||
@@ -217,7 +217,12 @@ export const secretSharingServiceFactory = ({
|
|||||||
if (accessType === SecretSharingAccessType.Organization && orgId !== sharedSecret.orgId)
|
if (accessType === SecretSharingAccessType.Organization && orgId !== sharedSecret.orgId)
|
||||||
throw new UnauthorizedError();
|
throw new UnauthorizedError();
|
||||||
|
|
||||||
const isMatch = await bcrypt.compare(password, sharedSecret.password);
|
if (!sharedSecret.password)
|
||||||
|
throw new InternalServerError({
|
||||||
|
message: "Something went wrong"
|
||||||
|
});
|
||||||
|
|
||||||
|
const isMatch = await bcrypt.compare(password, sharedSecret.password as string);
|
||||||
if (!isMatch) return undefined
|
if (!isMatch) return undefined
|
||||||
|
|
||||||
// we reduce the view count when we are sure the password matches.
|
// we reduce the view count when we are sure the password matches.
|
||||||
|
|||||||
@@ -43,32 +43,31 @@ export const useGetActiveSharedSecretById = ({
|
|||||||
sharedSecretId: string;
|
sharedSecretId: string;
|
||||||
hashedHex: string;
|
hashedHex: string;
|
||||||
}) => {
|
}) => {
|
||||||
return useQuery<TViewSharedSecretResponse, [string]>({
|
return useQuery<TViewSharedSecretResponse | null>(
|
||||||
enabled: Boolean(sharedSecretId) && Boolean(hashedHex),
|
[`sharedSecret-${sharedSecretId}`],
|
||||||
queryFn: async () => {
|
async () => {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({ hashedHex });
|
||||||
hashedHex
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data } = await apiRequest.get<TViewSharedSecretResponse>(
|
const { data } = await apiRequest.get<TViewSharedSecretResponse>(
|
||||||
`/api/v1/secret-sharing/public/${sharedSecretId}`,
|
`/api/v1/secret-sharing/public/${sharedSecretId}`,
|
||||||
{
|
{
|
||||||
params
|
params
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!data) return null;
|
if (!data) return null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
encryptedValue: data.encryptedValue,
|
encryptedValue: data.encryptedValue,
|
||||||
password: data.password,
|
|
||||||
iv: data.iv,
|
iv: data.iv,
|
||||||
tag: data.tag,
|
tag: data.tag,
|
||||||
accessType: data.accessType,
|
accessType: data.accessType,
|
||||||
orgName: data.orgName
|
orgName: data.orgName
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: Boolean(sharedSecretId) && Boolean(hashedHex)
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// returns a secret (secret or undefined if password doesn't match)
|
// returns a secret (secret or undefined if password doesn't match)
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import { TViewSharedSecretResponse, useGetActiveSharedSecretById } from "@app/ho
|
|||||||
import { SecretContainer, SecretErrorContainer, PasswordContainer } from "./components";
|
import { SecretContainer, SecretErrorContainer, PasswordContainer } from "./components";
|
||||||
|
|
||||||
export const ViewSecretPublicPage = () => {
|
export const ViewSecretPublicPage = () => {
|
||||||
const [secret, setSecret] = useState(null)
|
const [secret, setSecret] = useState<TViewSharedSecretResponse | null>(null);
|
||||||
const [error, setError] = useState(null)
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { id, key: urlEncodedPublicKey } = router.query;
|
const { id, key: urlEncodedPublicKey } = router.query;
|
||||||
|
|
||||||
@@ -19,15 +18,14 @@ export const ViewSecretPublicPage = () => {
|
|||||||
? urlEncodedPublicKey.toString().split("-")
|
? urlEncodedPublicKey.toString().split("-")
|
||||||
: ["", ""];
|
: ["", ""];
|
||||||
|
|
||||||
const { data: fetchSecret, error: fetchError, isLoading } = useGetActiveSharedSecretById({
|
const { data: fetchSecret, error, isLoading } = useGetActiveSharedSecretById({
|
||||||
sharedSecretId: id as string,
|
sharedSecretId: id as string,
|
||||||
hashedHex
|
hashedHex
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fetchSecret) setSecret(fetchSecret)
|
if (fetchSecret) setSecret(fetchSecret)
|
||||||
if (fetchError) setError(fetchError)
|
}, [fetchSecret, error])
|
||||||
}, [fetchSecret, fetchError])
|
|
||||||
|
|
||||||
const handleSecret = useCallback((value: TViewSharedSecretResponse) => {
|
const handleSecret = useCallback((value: TViewSharedSecretResponse) => {
|
||||||
setSecret(value)
|
setSecret(value)
|
||||||
|
|||||||
Reference in New Issue
Block a user