mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 20:25:43 +00:00
Fix case where user can get stuck in a deleted organization if they were prev logged into it
This commit is contained in:
@@ -24,10 +24,10 @@ import {
|
||||
User,
|
||||
UserEnc
|
||||
} from "./types";
|
||||
import { queryClient } from "@app/hooks/api/reactQuery";
|
||||
|
||||
export const fetchUserDetails = async () => {
|
||||
const { data } = await apiRequest.get<{ user: User & UserEnc }>("/api/v1/user");
|
||||
|
||||
return data.user;
|
||||
};
|
||||
|
||||
@@ -278,30 +278,33 @@ export const useRegisterUserAction = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useLogoutUser = (keepQueryClient?: boolean) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
await apiRequest.post("/api/v1/auth/logout");
|
||||
},
|
||||
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");
|
||||
sessionStorage.removeItem(SessionStorageKeys.CLI_TERMINAL_TOKEN);
|
||||
export const logoutUser = async () => {
|
||||
await apiRequest.post("/api/v1/auth/logout");
|
||||
};
|
||||
|
||||
if (!keepQueryClient) {
|
||||
queryClient.clear();
|
||||
}
|
||||
}
|
||||
// Utility function to clear session storage and query cache
|
||||
export const clearSession = (keepQueryClient?: boolean) => {
|
||||
setAuthToken(""); // Clear authentication token
|
||||
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");
|
||||
sessionStorage.removeItem(SessionStorageKeys.CLI_TERMINAL_TOKEN);
|
||||
|
||||
if (!keepQueryClient) {
|
||||
queryClient.clear(); // Clear React Query cache
|
||||
}
|
||||
};
|
||||
|
||||
export const useLogoutUser = (keepQueryClient?: boolean) => {
|
||||
return useMutation({
|
||||
mutationFn: logoutUser,
|
||||
onSuccess: () => clearSession(keepQueryClient)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user