Files
Nexus/docs/changelog/2026-06-07-refresh-token-null-version-fix.md
T
2026-07-08 22:31:31 +08:00

28 lines
949 B
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-07 — 修复 token_version=NULL 导致 refresh 失败自动登出
## 摘要
管理员 `token_version` 为 NULL 时,refresh cookie 含字面量 `:None`,续期解析失败 → 401 → 前端强制登出。
## 动机
用户反馈「刚刚又自动退出」;生产日志 `POST /api/auth/refresh 401`DB 中 `admins.token_version` 为 NULL。
## 变更
| 文件 | 说明 |
|------|------|
| `server/application/services/auth_service.py` | `_admin_token_version` / `_parse_refresh_token_version`;签发 refresh 用 `0` 而非 `None` |
| `server/infrastructure/database/migrations.py` | `UPDATE admins SET token_version=0 WHERE NULL` |
| `tests/test_refresh_token_null_version.py` | 回归测试 |
## 迁移 / 重启
API 重启后 migration 自动执行;**无需重新登录**(旧 `:None` cookie 仍可续期)。
## 验证
```bash
pytest tests/test_refresh_token_null_version.py tests/test_auth_refresh_reuse.py -q
```