(ctx: TRPCContext)
| 4 | import { type TRPCContext } from "../openApiTrpc"; |
| 5 | |
| 6 | export const requireWriteKey = async (ctx: TRPCContext) => { |
| 7 | if (!ctx.key) |
| 8 | throw new TRPCError({ |
| 9 | code: "UNAUTHORIZED", |
| 10 | message: "You must provide an API key to call this operation", |
| 11 | }); |
| 12 | |
| 13 | if (ctx.key?.readOnly) { |
| 14 | const project = await prisma.project.findUniqueOrThrow({ |
| 15 | where: { id: ctx.key.projectId }, |
| 16 | select: { slug: true }, |
| 17 | }); |
| 18 | |
| 19 | throw new TRPCError({ |
| 20 | code: "UNAUTHORIZED", |
| 21 | message: `You are trying to call a write operation with a read-only API key. Please view your project settings at ${env.NEXT_PUBLIC_HOST}/p/${project.slug}/settings and choose the "Read/Write" key.`, |
| 22 | }); |
| 23 | } |
| 24 | }; |
no outgoing calls
no test coverage detected