Your Name ea5a189ae0
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add agent admin settings access
2026-03-17 23:16:52 +08:00

39 lines
854 B
TypeScript

import { auth } from "@/app/(auth)/auth";
import { ChatSDKError } from "@/lib/errors";
export function isSiteAdminType(type?: string | null) {
return type === "admin";
}
export function isAgentWorkflowAdminType(type?: string | null) {
return type === "admin" || type === "agent_admin";
}
export async function requireAdmin() {
const session = await auth();
if (!session?.user) {
throw new ChatSDKError("unauthorized:admin");
}
if (!isSiteAdminType(session.user.type)) {
throw new ChatSDKError("forbidden:admin");
}
return session;
}
export async function requireAgentWorkflowAdmin() {
const session = await auth();
if (!session?.user) {
throw new ChatSDKError("unauthorized:admin");
}
if (!isAgentWorkflowAdminType(session.user.type)) {
throw new ChatSDKError("forbidden:admin");
}
return session;
}