cal.pub0.org/lib/utils/isAdmin.ts

8 lines
274 B
TypeScript

import { UserPermissionRole } from "@prisma/client";
export const isAdminGuard = async (req: NextApiRequest) => {
const { userId, prisma } = req;
const user = await prisma.user.findUnique({ where: { id: userId } });
return user?.role === UserPermissionRole.ADMIN;
};