Merge pull request #163 from calcom/fix/admin-me
fix: userId not 0 for fixing /me endpointpull/9078/head
commit
a36b6fa923
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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 };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue