feat: 管理界面改为 token 登录门禁

此前不填 token 也能进入各页面,只是没有内容。新增受鉴权保护的
/api/auth/session 探针与登录页,路由守卫在进入任何非登录页前先探针,
未通过则跳登录页并记住原目标;接口返回 401 时自动清 token 回登录页;
顶栏加退出按钮,撤掉设置页里的 token 卡片。本机未设 ADMIN_TOKEN 时
探针直接通过,开发体验不变。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-03 17:38:38 +08:00
parent 43a753963c
commit a3072ccbfb
7 changed files with 244 additions and 19 deletions

View File

@@ -22,6 +22,8 @@ const app = new Hono();
app.get('/api/health', (c) => c.json({ ok: true, name: 'proxy-station' }));
app.use('/api/*', adminAuth);
// 鉴权探针:能到这里说明已通过 adminAuthtoken 正确,或未设 token 且来源为本机/局域网)
app.get('/api/auth/session', (c) => c.json({ ok: true, tokenRequired: !!env.adminToken }));
app.route('/api/nodes', nodesRoute);
app.route('/api/groups', groupsRoute);
app.route('/api/rules', rulesRoute);