fix(登录态): 退出和换人登录时整页重载,不留上一个人的数据
signOut 只清了 profile 和 localStorage,AI 分析、学情小结等 store 还在内存里。
机房一台机器轮着用,下一个学生登进来就能看到上一个人的 AI 分析。
- 主动退出:router.replace 换成 window.location.replace("/")
- 被动下线(会话过期、别的标签页登出)仍然原地弹登录框,学生正在写的代码不丢;
getMyProfile 记住本页最后一个登录的用户,登进来的换了人就整页重载
挨个 store 去 reset 迟早漏一个,重载一次最彻底。
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb240d4254
commit
ca0dbbf0c5
2 files changed
+18
-2
No files matched your search
@@ -90,7 +90,9 @@ const active = computed(() => route.path.split("/")[1] || "problem")
|
|||||||
|
|
||||||
async function handleLogout() {
|
async function handleLogout() {
|
||||||
await userStore.signOut()
|
await userStore.signOut()
|
||||||
router.replace("/")
|
// 整页跳转而不是 router.replace:AI 分析、学情小结这些 store 还装着这个人的数据,
|
||||||
|
// 机房下一个学生坐下来就能看到。重载一次把内存清干净,比挨个 reset 可靠。
|
||||||
|
window.location.replace("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleToggleDemoMode() {
|
function handleToggleDemoMode() {
|
||||||
|
|||||||
@@ -66,11 +66,24 @@ export const useUserStore = defineStore("user", () => {
|
|||||||
// 登录后和改完设置仍然要能重新拉一份。
|
// 登录后和改完设置仍然要能重新拉一份。
|
||||||
let inflight: Promise<void> | null = null
|
let inflight: Promise<void> | null = null
|
||||||
|
|
||||||
|
// 这个页面生命周期里最后一个登录过的人。**clearProfile 不清它**,就是为了下面那道闸。
|
||||||
|
let lastUserId: number | null = null
|
||||||
|
|
||||||
function getMyProfile() {
|
function getMyProfile() {
|
||||||
if (inflight) return inflight
|
if (inflight) return inflight
|
||||||
isFinished.value = false
|
isFinished.value = false
|
||||||
inflight = getProfile()
|
inflight = getProfile()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
// 换了人就整页重载。会话过期、别的标签页登出这类被动下线是**原地**弹登录框
|
||||||
|
// 的(学生正在写的代码不能丢),可内存里的 store 全是上一个人的:AI 分析、
|
||||||
|
// 学情小结、协作状态……机房一台机器轮着用,下一个学生登进来就能看到。
|
||||||
|
// 挨个 store 去 reset 迟早漏一个,重载一次最彻底;同一个人重新登录不受影响。
|
||||||
|
const id = res?.user?.id ?? null
|
||||||
|
if (id !== null && lastUserId !== null && id !== lastUserId) {
|
||||||
|
window.location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (id !== null) lastUserId = id
|
||||||
profile.value = res
|
profile.value = res
|
||||||
isFinished.value = true
|
isFinished.value = true
|
||||||
storage.set(STORAGE_KEY.AUTHED, !!user.value?.email)
|
storage.set(STORAGE_KEY.AUTHED, !!user.value?.email)
|
||||||
@@ -90,7 +103,8 @@ export const useUserStore = defineStore("user", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 退登的两步(吊销服务端会话、清本地状态)绑在一起:只清本地会留一个还活着
|
// 退登的两步(吊销服务端会话、清本地状态)绑在一起:只清本地会留一个还活着
|
||||||
// 的 cookie,下次进站又被 /profile 认回来。跳转留给调用方,store 里不碰路由。
|
// 的 cookie,下次进站又被 /profile 认回来。跳转留给调用方,store 里不碰路由 ——
|
||||||
|
// 调用方要**整页**跳走,别用 router:各个 store 里还留着这个人的数据。
|
||||||
async function signOut() {
|
async function signOut() {
|
||||||
await logout()
|
await logout()
|
||||||
clearProfile()
|
clearProfile()
|
||||||
|
|||||||
Reference in new issue
Block a user