mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
Fix log out endless loop which occurred on slow connections and could tear down the SCM-Manager server.
This commit is contained in:
2
gradle/changelog/logout_endless_loop.yaml
Normal file
2
gradle/changelog/logout_endless_loop.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
- type: fixed
|
||||||
|
description: Fix logout endless loop on slow connections
|
||||||
@@ -28,17 +28,18 @@ import { apiClient } from "./apiclient";
|
|||||||
import { ApiResult, useIndexLink } from "./base";
|
import { ApiResult, useIndexLink } from "./base";
|
||||||
import { useLegacyContext } from "./LegacyContext";
|
import { useLegacyContext } from "./LegacyContext";
|
||||||
import { useReset } from "./reset";
|
import { useReset } from "./reset";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
|
||||||
export const useMe = (): ApiResult<Me> => {
|
export const useMe = (): ApiResult<Me> => {
|
||||||
const legacy = useLegacyContext();
|
const legacy = useLegacyContext();
|
||||||
const link = useIndexLink("me");
|
const link = useIndexLink("me");
|
||||||
return useQuery<Me, Error>("me", () => apiClient.get(link!).then((response) => response.json()), {
|
return useQuery<Me, Error>("me", () => apiClient.get(link!).then(response => response.json()), {
|
||||||
enabled: !!link,
|
enabled: !!link,
|
||||||
onSuccess: (me) => {
|
onSuccess: me => {
|
||||||
if (legacy.onMeFetched) {
|
if (legacy.onMeFetched) {
|
||||||
legacy.onMeFetched(me);
|
legacy.onMeFetched(me);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ export const useSubject = () => {
|
|||||||
isAnonymous,
|
isAnonymous,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
me,
|
me
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,9 +76,9 @@ export const useLogin = () => {
|
|||||||
const link = useIndexLink("login");
|
const link = useIndexLink("login");
|
||||||
const reset = useReset();
|
const reset = useReset();
|
||||||
const { mutate, isLoading, error } = useMutation<unknown, Error, Credentials>(
|
const { mutate, isLoading, error } = useMutation<unknown, Error, Credentials>(
|
||||||
(credentials) => apiClient.post(link!, credentials),
|
credentials => apiClient.post(link!, credentials),
|
||||||
{
|
{
|
||||||
onSuccess: reset,
|
onSuccess: reset
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ export const useLogin = () => {
|
|||||||
return {
|
return {
|
||||||
login: link ? login : undefined,
|
login: link ? login : undefined,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,24 +105,24 @@ export const useLogout = () => {
|
|||||||
const reset = useReset();
|
const reset = useReset();
|
||||||
|
|
||||||
const { mutate, isLoading, error, data } = useMutation<LogoutResponse, Error, unknown>(
|
const { mutate, isLoading, error, data } = useMutation<LogoutResponse, Error, unknown>(
|
||||||
() => apiClient.delete(link!).then((r) => (r.status === 200 ? r.json() : {})),
|
() => apiClient.delete(link!).then(r => (r.status === 200 ? r.json() : {})),
|
||||||
{
|
{
|
||||||
onSuccess: (response) => {
|
onSuccess: response => {
|
||||||
if (response?.logoutRedirect) {
|
if (response?.logoutRedirect) {
|
||||||
window.location.assign(response.logoutRedirect);
|
window.location.assign(response.logoutRedirect);
|
||||||
}
|
}
|
||||||
return reset();
|
return reset();
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const logout = () => {
|
const logout = useCallback(() => {
|
||||||
mutate({});
|
mutate({});
|
||||||
};
|
}, [mutate]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
logout: link && !data ? logout : undefined,
|
logout: link && !data ? logout : undefined,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user