Merge pull request #2865 from Infisical/daniel/fix-reminder-cleanup

fix(secret-reminders): proper cleanup on deleted resources
This commit is contained in:
Daniel Hougaard
2024-12-18 02:57:07 +01:00
committed by GitHub
19 changed files with 471 additions and 126 deletions
+7 -2
View File
@@ -77,11 +77,16 @@ export const selectOrganization = async (data: {
export const useSelectOrganization = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (details: { organizationId: string; userAgent?: UserAgentType }) => {
mutationFn: async (details: {
organizationId: string;
userAgent?: UserAgentType;
forceSetCredentials?: boolean;
}) => {
const data = await selectOrganization(details);
// If a custom user agent is set, then this session is meant for another consuming application, not the web application.
if (!details.userAgent && !data.isMfaEnabled) {
if ((!details.userAgent && !data.isMfaEnabled) || details.forceSetCredentials) {
localStorage.setItem("orgData.id", details.organizationId);
SecurityClient.setToken(data.token);
SecurityClient.setProviderAuthToken("");
}
@@ -1,5 +1,6 @@
import { useMutation, useQuery, useQueryClient, UseQueryOptions } from "@tanstack/react-query";
import SecurityClient from "@app/components/utilities/SecurityClient";
import { apiRequest } from "@app/config/request";
import { OrderByDirection } from "@app/hooks/api/generic/types";
@@ -67,7 +68,7 @@ export const useCreateOrg = (options: { invalidate: boolean } = { invalidate: tr
mutationFn: async ({ name }: { name: string }) => {
const {
data: { organization }
} = await apiRequest.post("/api/v2/organizations", {
} = await apiRequest.post<{ organization: { id: string } }>("/api/v2/organizations", {
name
});
@@ -437,10 +438,13 @@ export const useDeleteOrgById = () => {
return useMutation({
mutationFn: async ({ organizationId }: { organizationId: string }) => {
const {
data: { organization }
} = await apiRequest.delete<{ organization: Organization }>(
data: { organization, accessToken }
} = await apiRequest.delete<{ organization: Organization; accessToken: string }>(
`/api/v2/organizations/${organizationId}`
);
SecurityClient.setToken(accessToken);
localStorage.removeItem("orgData.id");
return organization;
},
onSuccess(_, dto) {