MCPcopy
hub / github.com/OpenPipe/OpenPipe / requireIsProjectAdmin

Function requireIsProjectAdmin

app/src/utils/accessControl.ts:92–111  ·  view source on GitHub ↗
(projectId: string, ctx: TRPCContext)

Source from the content-addressed store, hash-verified

90};
91
92export const requireIsProjectAdmin = async (projectId: string, ctx: TRPCContext) => {
93 ctx.markAccessControlRun();
94
95 const userId = requireUserId(ctx);
96
97 const isAdmin = await prisma.projectUser.findFirst({
98 where: {
99 userId,
100 projectId,
101 role: { in: [ProjectUserRole.OWNER, ProjectUserRole.ADMIN] },
102 },
103 });
104
105 if (!isAdmin) {
106 throw new TRPCError({
107 code: "UNAUTHORIZED",
108 message: "Only project admins can perform this action.",
109 });
110 }
111};
112
113export const requireIsAdmin = async (ctx: TRPCContext) => {
114 ctx.markAccessControlRun();

Callers 4

projects.router.tsFile · 0.90
users.router.tsFile · 0.90
payments.router.tsFile · 0.90
exportWeights.tsFile · 0.90

Calls 1

requireUserIdFunction · 0.85

Tested by

no test coverage detected