refactor: 拆分工作台业务服务边界

This commit is contained in:
que01 committed 2026-10-12 03:29:30 +08:00
1 parent d0902d6568
commit 4512d2601d
5 files changed
+228 -164

No files matched your search

@@ -0,0 +1,23 @@
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";
};
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;
}