fix: 收口审查发现的 CI 与授权边界

将 admin identity helper 移到共享边界,清理跨 feature 导入;修复 CI 集成环境、浏览器数据库/Playwright 配置;增强 doctor source hash 对重命名文件的处理,并补充 logout API 文档。
This commit is contained in:
que01 committed 2026-10-19 00:28:37 +08:00
1 parent bd129a3069
commit 0788480ce3
12 files changed
+35 -16

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { ForbiddenException, UnauthorizedException } from "@nestjs/common";
import type { FastifyRequest } from "fastify";
import { readIdentity } from "./auth.js";
export type AdminIdentity = {
subject: string;
brandId: string;
role: "admin";
tokenVersion: number;
};
export function requireAdminIdentity(request: FastifyRequest): AdminIdentity {
const token = request.headers.authorization?.replace(/^Bearer\s+/i, "");
if (!token) throw new UnauthorizedException("缺少管理员登录态");
let identity;
try {
identity = readIdentity(token);
} catch {
throw new UnauthorizedException("管理员登录态无效或已过期");
}
if (identity.role !== "admin") throw new ForbiddenException("无管理员权限");
return identity as AdminIdentity;
}