From 49195fd2e17a7ac3d648a42f1842e686b62e4b76 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 9 Nov 2021 16:17:42 +0100 Subject: [PATCH] Fix log out endless loop which occurred on slow connections and could tear down the SCM-Manager server. --- gradle/changelog/logout_endless_loop.yaml | 2 ++ scm-ui/ui-api/src/login.ts | 27 ++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 gradle/changelog/logout_endless_loop.yaml diff --git a/gradle/changelog/logout_endless_loop.yaml b/gradle/changelog/logout_endless_loop.yaml new file mode 100644 index 0000000000..5dbe2fd4f5 --- /dev/null +++ b/gradle/changelog/logout_endless_loop.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Fix logout endless loop on slow connections diff --git a/scm-ui/ui-api/src/login.ts b/scm-ui/ui-api/src/login.ts index d68432ce39..00bc5c28a8 100644 --- a/scm-ui/ui-api/src/login.ts +++ b/scm-ui/ui-api/src/login.ts @@ -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 => { const legacy = useLegacyContext(); const link = useIndexLink("me"); - return useQuery("me", () => apiClient.get(link!).then((response) => response.json()), { + return useQuery("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( - (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( - () => 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 }; };