Guanghu Domestic Migration a27e87cb99 chore: import sanitized domestic snapshot for REPO-007
Source snapshot: 97d7f0fae96dc04b7ddad56fc1db6a108ed662cc

[SEC-CLEAN] · pre-push-clean v1.0 · 109处敏感信息已自动转乱码
2026-07-17 15:59:55 +08:00

50 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 执行记录 · 2026-06-09 · GHCS v0.2 API Keys 鉴权修复与本地验收
```jsx
HLDP://ghcs/v0.2/exec-log/2026-06-09 · 2026-06-09T00:56+08:00
├── scope: GHCS v0.2 · API Keys 管理
├── goal: keys 页面写操作不再 401完成本地闭环验收
├── env: Mac 本地开发frontend + backend
└── result: 完成
```
---
## ✅ 今日完成清单(按验收口径)
- 后端已挂载 keys 路由:`GET /api/keys/suppliers` 返回 200
- 鉴权链路跑通:`POST /api/login` 返回 `access_token`bearer
- 写入验收:`POST /api/keys/add` 写入成功(示例 id`41f67eb681f3`mask 显示正确
- 读回验收:`GET /api/keys/list` 可读回刚写入的 key
- 前端页面 `/console/keys` 联调通过suppliers/list/usage/health-check 200
- 关键修复前端写操作PUT/DELETE/POST补齐 `Authorization: Bearer`,启停 `PUT /api/keys/{id}` 从 401 → 200
---
## 🔑 关键数据(防遗忘)
### 端口与环境变量
- backend`http://127.0.0.1:5002`
- frontend`http://localhost:3000`
- `frontend/.env.local``NEXT_PUBLIC_CONSOLE_API=http://127.0.0.1:5002`
- ⊢ 改 env 必须重启 `npm run dev`
### token 规则
- `/api/login` 返回字段:`access_token`
- 前端存 token`localStorage.ghcs_access_token`
- 写请求头:`Authorization: Bearer <access_token>`
### 本地默认账号(见 backend/[auth.py](http://auth.py)
- `awen / guanghu2026`
---
## 🧠 交互产生的认知(可迁移)
- **页面 200 ≠ 链路通**:先用 `curl -i` 看 200/404再谈 UI。
- **env 改了不重启 = 没改**Next 必须重启才会吃新 `.env.local`
- **读接口可放开,写接口必须鉴权**:前端所有写 fetch 必须统一带 Bearer。
- **用最小证据验收**Network 里看 `PUT` 从 401→200 是“根治完成”的唯一判据。