19 lines
426 B
TypeScript
19 lines
426 B
TypeScript
import type { Actor } from "@/lib/actor"
|
|
import type { ApiDecision } from "@/lib/errors"
|
|
|
|
export function allow(): ApiDecision {
|
|
return { ok: true }
|
|
}
|
|
|
|
export function deny(code: number, msg: string): ApiDecision {
|
|
return { ok: false, error: { code, msg } }
|
|
}
|
|
|
|
export function requireAuth(actor: Actor | null | undefined): ApiDecision {
|
|
if (!actor?.userId) {
|
|
return deny(401, "请先登录")
|
|
}
|
|
|
|
return allow()
|
|
}
|