From 1c89638f7e724a0f95700ab25850ec05fb9cd549 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 23 Mar 2023 22:52:34 +0800 Subject: [PATCH] fix: unable to login again after using oauth providers login (#3571) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area console #### What this PR does / why we need it: 修复使用非本地认证登录之后,无法重新登录的问题。此问题来源是三方登录方式登录之后没有在 localStorage 存入 `logged_in` 的 flag。并且在引入匿名用户之后,本身也不再需要这个 flag。 #### Which issue(s) this PR fixes: Fixes #3569 #### Special notes for your reviewer: 测试方式: 1. 使用 https://github.com/halo-sigs/plugin-oauth2/pull/3 插件配置 OAuth 2 的登录方式。 2. 在个人资料中绑定配置的登录方式。 3. 测试登录之后退出,再进行登录。 #### Does this PR introduce a user-facing change? ```release-note None ``` --- console/src/components/login/LoginForm.vue | 2 -- console/src/router/guards/auth-check.ts | 2 +- console/src/utils/api-client.ts | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/console/src/components/login/LoginForm.vue b/console/src/components/login/LoginForm.vue index 4e25c18ee..b73d82e94 100644 --- a/console/src/components/login/LoginForm.vue +++ b/console/src/components/login/LoginForm.vue @@ -70,8 +70,6 @@ const handleLogin = async () => { await userStore.fetchCurrentUser(); - localStorage.setItem("logged_in", "true"); - emit("succeed"); } catch (e: unknown) { console.error("Failed to login", e); diff --git a/console/src/router/guards/auth-check.ts b/console/src/router/guards/auth-check.ts index f2c5f393b..bb3d2fde8 100644 --- a/console/src/router/guards/auth-check.ts +++ b/console/src/router/guards/auth-check.ts @@ -10,7 +10,7 @@ export function setupAuthCheckGuard(router: Router) { const userStore = useUserStore(); - if (localStorage.getItem("logged_in") !== "true" || userStore.isAnonymous) { + if (userStore.isAnonymous) { next({ name: "Login" }); return; } diff --git a/console/src/utils/api-client.ts b/console/src/utils/api-client.ts index 655af48bd..a61aa5710 100644 --- a/console/src/utils/api-client.ts +++ b/console/src/utils/api-client.ts @@ -94,7 +94,6 @@ axiosInstance.interceptors.response.use( const userStore = useUserStore(); userStore.loginModalVisible = true; Toast.warning(i18n.global.t("core.common.toast.login_expired")); - localStorage.removeItem("logged_in"); } else if (status === 403) { Toast.error(i18n.global.t("core.common.toast.forbidden")); } else if (status === 404) {