mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
refactor: convert usequery hook to normal fetch fn (no need for caching)
This commit is contained in:
@@ -68,29 +68,18 @@ export const useGetActiveSharedSecretById = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useValidateSecretPassword = ({
|
export const fetchIsSecretPasswordValid = async (
|
||||||
sharedSecretId,
|
sharedSecretId: string,
|
||||||
hashedHex,
|
hashedHex: string,
|
||||||
userPassword,
|
password: string,
|
||||||
}: {
|
) => {
|
||||||
sharedSecretId: string;
|
const { data } = await apiRequest.post<ValidateSecretPassword>(
|
||||||
hashedHex: string;
|
`/api/v1/secret-sharing/public/${sharedSecretId}/validate`,
|
||||||
userPassword: string;
|
|
||||||
}) => {
|
|
||||||
return useQuery(
|
|
||||||
[`validateSecretPass-${sharedSecretId}`],
|
|
||||||
async () => {
|
|
||||||
const { data } = await apiRequest.post<ValidateSecretPassword>(
|
|
||||||
`/api/v1/secret-sharing/public/${sharedSecretId}/validate`,
|
|
||||||
{
|
|
||||||
hashedHex,
|
|
||||||
password: userPassword
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
enabled: Boolean(sharedSecretId) && Boolean(userPassword),
|
hashedHex,
|
||||||
|
password
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
}
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { faArrowRight, faSpinner } from "@fortawesome/free-solid-svg-icons";
|
|||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
import { Button, IconButton, Input } from "@app/components/v2";
|
import { Button, IconButton, Input } from "@app/components/v2";
|
||||||
import { useValidateSecretPassword } from "@app/hooks/api/secretSharing";
|
import { fetchIsSecretPasswordValid } from "@app/hooks/api/secretSharing";
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -16,11 +16,6 @@ type Props = {
|
|||||||
export const PasswordContainer = ({ secretId, hashedHex, handlePassMatch }: Props) => {
|
export const PasswordContainer = ({ secretId, hashedHex, handlePassMatch }: Props) => {
|
||||||
const [password, setPassword] = useState<string>('')
|
const [password, setPassword] = useState<string>('')
|
||||||
const [isLoading, setLoading] = useState(false)
|
const [isLoading, setLoading] = useState(false)
|
||||||
const { refetch } = useValidateSecretPassword({
|
|
||||||
sharedSecretId: secretId,
|
|
||||||
hashedHex,
|
|
||||||
userPassword: password,
|
|
||||||
})
|
|
||||||
|
|
||||||
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
setPassword(e.target.value)
|
setPassword(e.target.value)
|
||||||
@@ -30,9 +25,13 @@ export const PasswordContainer = ({ secretId, hashedHex, handlePassMatch }: Prop
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data: freshData } = await refetch();
|
const data = await fetchIsSecretPasswordValid(
|
||||||
|
secretId,
|
||||||
|
hashedHex,
|
||||||
|
password,
|
||||||
|
)
|
||||||
|
|
||||||
if (freshData?.isValid === true) {
|
if (data?.isValid === true) {
|
||||||
handlePassMatch(true);
|
handlePassMatch(true);
|
||||||
} else {
|
} else {
|
||||||
createNotification({
|
createNotification({
|
||||||
|
|||||||
Reference in New Issue
Block a user