mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 20:26:44 +00:00
Make merge user step automatic after email verification
This commit is contained in:
@@ -5,11 +5,9 @@ import {
|
||||
encryptAssymmetric
|
||||
} from "@app/components/utilities/cryptography/crypto";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { setAuthToken } from "@app/reactQuery";
|
||||
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
import { userKeys } from "./queries";
|
||||
import { AddUserToWsDTOE2EE, AddUserToWsDTONonE2EE, User } from "./types";
|
||||
import { AddUserToWsDTOE2EE, AddUserToWsDTONonE2EE } from "./types";
|
||||
|
||||
export const useAddUserToWsE2EE = () => {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -64,58 +62,29 @@ export const useAddUserToWsNonE2EE = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const sendEmailVerificationCode = async () => {
|
||||
return apiRequest.post("/api/v2/users/me/emails/code");
|
||||
export const sendEmailVerificationCode = async (username: string) => {
|
||||
return apiRequest.post("/api/v2/users/me/emails/code", {
|
||||
username
|
||||
});
|
||||
};
|
||||
|
||||
export const useSendEmailVerificationCode = () => {
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
await sendEmailVerificationCode();
|
||||
mutationFn: async (username: string) => {
|
||||
await sendEmailVerificationCode(username);
|
||||
return {};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useVerifyEmailVerificationCode = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ code }: { code: string }) => {
|
||||
mutationFn: async ({ username, code }: { username: string; code: string }) => {
|
||||
await apiRequest.post("/api/v2/users/me/emails/verify", {
|
||||
username,
|
||||
code
|
||||
});
|
||||
return {};
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(userKeys.usersWithMyEmail);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useMergeUsers = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({ username }: { username: string }) => {
|
||||
const { data } = await apiRequest.post<{ user: User }>("/api/v2/users/me/users/merge-user", {
|
||||
username
|
||||
});
|
||||
return data;
|
||||
},
|
||||
onSuccess: () => {
|
||||
setAuthToken("");
|
||||
// Delete the cookie by not setting a value; Alternatively clear the local storage
|
||||
localStorage.removeItem("protectedKey");
|
||||
localStorage.removeItem("protectedKeyIV");
|
||||
localStorage.removeItem("protectedKeyTag");
|
||||
localStorage.removeItem("publicKey");
|
||||
localStorage.removeItem("encryptedPrivateKey");
|
||||
localStorage.removeItem("iv");
|
||||
localStorage.removeItem("tag");
|
||||
localStorage.removeItem("PRIVATE_KEY");
|
||||
localStorage.removeItem("orgData.id");
|
||||
localStorage.removeItem("projectData.id");
|
||||
|
||||
queryClient.clear();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user