refactor(policy): add centralized decision helpers

This commit is contained in:
zetaloop
2026-02-22 14:50:54 +08:00
parent d0d21fa935
commit 03fa447864
3 changed files with 42 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import type { Actor } from "@/lib/policy/actor"
import type { PolicyDecision, ReasonCode } from "@/lib/policy/decision"
export function allow(): PolicyDecision {
return { ok: true }
}
export function deny(reasonCode: ReasonCode, message?: string): PolicyDecision {
return { ok: false, reasonCode, message }
}
export function requireAuth(actor: Actor | null | undefined): PolicyDecision {
if (!actor?.userId) {
return deny("AUTH_REQUIRED", "请先登录")
}
return allow()
}