From 596ceec880b488a464ac18c732948205bbf5f3ac Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Wed, 10 Jun 2026 20:29:40 -0600 Subject: [PATCH] fix --- src/components/Login.vue | 7 +++++++ src/router.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Login.vue b/src/components/Login.vue index 2142d82..79e57ec 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -103,6 +103,7 @@ import { ref, computed, onMounted } from "vue" import { Account } from "../api" import { loginModal } from "../store/modal" import { user } from "../store/user" +import { router } from "../router" // Tab state const activeTab = ref("student") @@ -190,6 +191,9 @@ async function submitStudent() { user.role = data.role user.loaded = true loginModal.value = false + router.replace( + window.location.pathname + window.location.search + window.location.hash, + ) } catch { showStudentError.value = true } finally { @@ -207,6 +211,9 @@ async function submitAdmin() { user.role = data.role user.loaded = true loginModal.value = false + router.replace( + window.location.pathname + window.location.search + window.location.hash, + ) } catch { showAdminError.value = true } finally { diff --git a/src/router.ts b/src/router.ts index 2d8764b..6348417 100644 --- a/src/router.ts +++ b/src/router.ts @@ -3,6 +3,7 @@ import { loginModal } from "./store/modal" import Workspace from "./pages/Workspace.vue" import { STORAGE_KEY } from "./utils/const" +import { authed } from "./store/user" const routes = [ { path: "/", name: "home", component: Workspace, meta: { auth: true } }, @@ -75,7 +76,8 @@ export const router = createRouter({ }) router.beforeEach((to) => { - const isLoggedIn = localStorage.getItem(STORAGE_KEY.LOGIN) === "true" + const isLoggedIn = + authed.value || localStorage.getItem(STORAGE_KEY.LOGIN) === "true" if (to.meta.auth && !isLoggedIn) { loginModal.value = true return false