From 934a8947c8e3d64e0ba5e821c400ed2deea893d5 Mon Sep 17 00:00:00 2001 From: ZhaoYP 2001 <75831053+ZhaoYP-2001@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:31:37 +0800 Subject: [PATCH] feat: fix CAS logout failure caused by Beego session update problem (#3194) * feat: fix the cas logout failure caused by beego session update problem * fix: simplify the implementation of logout timer * fix: change the location of the login success code * fix: add i18n to CasLogout.js --- web/src/auth/CasLogout.js | 41 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/web/src/auth/CasLogout.js b/web/src/auth/CasLogout.js index 262841d3..557738db 100644 --- a/web/src/auth/CasLogout.js +++ b/web/src/auth/CasLogout.js @@ -34,25 +34,42 @@ class CasLogout extends React.Component { UNSAFE_componentWillMount() { const params = new URLSearchParams(this.props.location.search); + const logoutInterval = 100; + + const logoutTimeOut = (redirectUri) => { + setTimeout(() => { + AuthBackend.getAccount().then((accountRes) => { + if (accountRes.status === "ok") { + AuthBackend.logout().then((logoutRes) => { + if (logoutRes.status === "ok") { + logoutTimeOut(logoutRes.data2); + } else { + Setting.showMessage("error", `${i18next.t("login:Failed to log out")}: ${logoutRes.msg}`); + } + }); + } else { + Setting.showMessage("success", i18next.t("application:Logged out successfully")); + this.props.onUpdateAccount(null); + if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") { + Setting.goToLink(redirectUri); + } else if (params.has("service")) { + Setting.goToLink(params.get("service")); + } else { + Setting.goToLinkSoft(this, `/cas/${this.state.owner}/${this.state.applicationName}/login`); + } + } + }); + }, logoutInterval); + }; AuthBackend.logout() .then((res) => { if (res.status === "ok") { - Setting.showMessage("success", "Logged out successfully"); - this.props.onUpdateAccount(null); - const redirectUri = res.data2; - if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") { - Setting.goToLink(redirectUri); - } else if (params.has("service")) { - Setting.goToLink(params.get("service")); - } else { - Setting.goToLinkSoft(this, `/cas/${this.state.owner}/${this.state.applicationName}/login`); - } + logoutTimeOut(res.data2); } else { - Setting.showMessage("error", `Failed to log out: ${res.msg}`); + Setting.showMessage("error", `${i18next.t("login:Failed to log out")}: ${res.msg}`); } }); - } render() {