diff --git a/lib/helpers/customPrisma.ts b/lib/helpers/customPrisma.ts index f2d038c5e5..f374048499 100644 --- a/lib/helpers/customPrisma.ts +++ b/lib/helpers/customPrisma.ts @@ -47,7 +47,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => { we skip verifyApiKey logic and pass onto next middleware instead. */ req.isAdmin = true; - req.userId = 0; + req.isCustomPrisma = true; await next(); }; diff --git a/lib/helpers/extendRequest.ts b/lib/helpers/extendRequest.ts index 2924782d3e..d01cce81e2 100644 --- a/lib/helpers/extendRequest.ts +++ b/lib/helpers/extendRequest.ts @@ -15,6 +15,7 @@ declare module "next" { session: { user: { id: number } }; query: Partial<{ [key: string]: string | string[] }>; isAdmin: boolean; + isCustomPrisma: boolean; pagination: { take: number; skip: number }; } } diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 408cc55356..ee252d91fd 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -18,9 +18,9 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { const hasValidLicense = await checkLicense(process.env.CALCOM_LICENSE_KEY || ""); if (!hasValidLicense) return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" }); - const { prisma, userId, isAdmin } = req; + const { prisma, isCustomPrisma, isAdmin } = req; // If the user is an admin and using a license key (from customPrisma), skip the apiKey check. - if (userId === 0 && isAdmin) { + if (isCustomPrisma && isAdmin) { await next(); return; } @@ -42,6 +42,6 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => { req.userId = apiKey.userId; // save the isAdmin boolean here for later use req.isAdmin = await isAdminGuard(req); - + req.isCustomPrisma = false; await next(); };