fix(filelib-web): 退出登录后管理后台真正跳回登录页

管理后台外壳把「未登录跳 /database/admin」写在 onMount 里,只判断一次。
但 logout() 只清前端 store(它与老师端 /app 共用,那边 me=null 是终态、
不跳转),退出后这层壳重新渲染进 me===null 分支,onMount 不会再跑,
于是永远停在「跳转到登录页…」。

把这道权限门移到 $effect,对任何一次「变成未登录」都生效。条件里的
$authChecked 是必要的 —— 否则首屏 session 请求未回时 me 仍是初始 null,
会把已登录用户直接弹去登录页。

顺带修好「无权访问管理后台」分支里同一个死胡同的退出按钮。
/auth/logout 的 204 本身没有问题。
This commit is contained in:
2026-07-27 14:24:11 +08:00
parent 50ddf32cc2
commit a306c58db2
@@ -28,9 +28,18 @@
const BASE = "/database/dashboard"; const BASE = "/database/dashboard";
onMount(async () => { onMount(loadSession);
await loadSession();
if ($me === null) void goto("/database/admin", { replaceState: true }); /**
* 未登录一律回登录页 —— 必须是 effect 而非 onMount 里的一次性判断:
* `logout()` 只清 store(它被老师端 /app 共用,那边 me=null 是终态而非跳转),
* 退出后这层壳会重新渲染成 me===null,若跳转只写在 onMount 就永远停在
* "跳转到登录页…"。
*/
$effect(() => {
if ($authChecked && $me === null) {
void goto("/database/admin", { replaceState: true });
}
}); });
function href(seg: string): string { function href(seg: string): string {