fix: make isAdmin require req.prisma too
This commit is contained in:
1 parent
cc534a2914
commit
60688e2e91
8 files changed
+10
-12
No files matched your search
@@ -34,7 +34,7 @@ export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
||||
/* We save the user id in the request for later use */
|
||||
req.userId = apiKey.userId;
|
||||
/* We save the isAdmin boolean here for later use */
|
||||
req.isAdmin = await isAdminGuard(req.userId);
|
||||
req.isAdmin = await isAdminGuard(req.userId, prisma);
|
||||
|
||||
await next();
|
||||
};
|
||||
@@ -1,8 +1,6 @@
|
||||
import { UserPermissionRole } from "@prisma/client";
|
||||
import { PrismaClient, UserPermissionRole } from "@prisma/client";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export const isAdminGuard = async (userId: number) => {
|
||||
export const isAdminGuard = async (userId: number, prisma: PrismaClient) => {
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
return user?.role === UserPermissionRole.ADMIN;
|
||||
};
|
||||
@@ -7,7 +7,7 @@ export type GetSubscriberOptions = {
|
||||
eventTypeId: number;
|
||||
triggerEvent: WebhookTriggerEvents;
|
||||
};
|
||||
|
||||
/** @note will this not work with custom prisma? since we're importing prisma directly and not passing it from request here **/
|
||||
const getWebhooks = async (options: GetSubscriberOptions) => {
|
||||
const { userId, eventTypeId } = options;
|
||||
const allWebhooks = await prisma.webhook.findMany({
|
||||
|
||||
Reference in new issue
Block a user