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:
@@ -28,17 +28,18 @@ import { apiClient } from "./apiclient";
|
||||
import { ApiResult, useIndexLink } from "./base";
|
||||
import { useLegacyContext } from "./LegacyContext";
|
||||
import { useReset } from "./reset";
|
||||
import { useCallback } from "react";
|
||||
|
||||
export const useMe = (): ApiResult<Me> => {
|
||||
const legacy = useLegacyContext();
|
||||
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,
|
||||
onSuccess: (me) => {
|
||||
onSuccess: me => {
|
||||
if (legacy.onMeFetched) {
|
||||
legacy.onMeFetched(me);
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -60,7 +61,7 @@ export const useSubject = () => {
|
||||
isAnonymous,
|
||||
isLoading,
|
||||
error,
|
||||
me,
|
||||
me
|
||||
};
|
||||
};
|
||||
|
||||
@@ -75,9 +76,9 @@ export const useLogin = () => {
|
||||
const link = useIndexLink("login");
|
||||
const reset = useReset();
|
||||
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 {
|
||||
login: link ? login : undefined,
|
||||
isLoading,
|
||||
error,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
@@ -104,24 +105,24 @@ export const useLogout = () => {
|
||||
const reset = useReset();
|
||||
|
||||
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) {
|
||||
window.location.assign(response.logoutRedirect);
|
||||
}
|
||||
return reset();
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const logout = () => {
|
||||
const logout = useCallback(() => {
|
||||
mutate({});
|
||||
};
|
||||
}, [mutate]);
|
||||
|
||||
return {
|
||||
logout: link && !data ? logout : undefined,
|
||||
isLoading,
|
||||
error,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user