fix: resolve issue with logout functionality in Console not working (#6766)

#### What type of PR is this?

/area ui
/kind bug
/milestone 2.20.x

#### What this PR does / why we need it:

修复 Console 中退出登录功能失效的问题。

#### Which issue(s) this PR fixes:

Fixes #6756 

#### Does this PR introduce a user-facing change?

```release-note
None
```
This commit is contained in:
Ryan Wang
2024-10-05 14:38:44 +08:00
committed by GitHub
parent 8896e16615
commit b0ad0406b9
5 changed files with 7 additions and 32 deletions

View File

@@ -17,7 +17,6 @@ import {
VTag,
} from "@halo-dev/components";
import { useEventListener } from "@vueuse/core";
import axios from "axios";
import {
useOverlayScrollbars,
type UseOverlayScrollbarsParams,
@@ -42,24 +41,11 @@ const { currentRoles, currentUser } = storeToRefs(userStore);
const handleLogout = () => {
Dialog.warning({
title: t("core.sidebar.operations.logout.title"),
description: t("core.sidebar.operations.logout.description"),
confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
try {
await axios.post(`/logout`, undefined, {
withCredentials: true,
});
await userStore.fetchCurrentUser();
// Clear csrf token
document.cookie =
"XSRF-TOKEN=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
window.location.href = "/login";
} catch (error) {
console.error("Failed to logout", error);
}
window.location.href = "/logout";
},
});
};