fix: userId not 0 for fixing /me endpoint

pull/9078/head
Agusti Fernandez Pardo 2022-09-07 18:18:43 +02:00
parent fcb9ca6ace
commit be200cd076
3 changed files with 5 additions and 4 deletions

View File

@ -47,7 +47,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => {
we skip verifyApiKey logic and pass onto next middleware instead. we skip verifyApiKey logic and pass onto next middleware instead.
*/ */
req.isAdmin = true; req.isAdmin = true;
req.userId = 0; req.isCustomPrisma = true;
await next(); await next();
}; };

View File

@ -15,6 +15,7 @@ declare module "next" {
session: { user: { id: number } }; session: { user: { id: number } };
query: Partial<{ [key: string]: string | string[] }>; query: Partial<{ [key: string]: string | string[] }>;
isAdmin: boolean; isAdmin: boolean;
isCustomPrisma: boolean;
pagination: { take: number; skip: number }; pagination: { take: number; skip: number };
} }
} }

View File

@ -18,9 +18,9 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => {
const hasValidLicense = await checkLicense(process.env.CALCOM_LICENSE_KEY || ""); const hasValidLicense = await checkLicense(process.env.CALCOM_LICENSE_KEY || "");
if (!hasValidLicense) if (!hasValidLicense)
return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" }); 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 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(); await next();
return; return;
} }
@ -42,6 +42,6 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => {
req.userId = apiKey.userId; req.userId = apiKey.userId;
// save the isAdmin boolean here for later use // save the isAdmin boolean here for later use
req.isAdmin = await isAdminGuard(req); req.isAdmin = await isAdminGuard(req);
req.isCustomPrisma = false;
await next(); await next();
}; };