fix: userId not 0 for fixing /me endpoint
parent
fcb9ca6ace
commit
be200cd076
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue