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

9 lines
324 B
TypeScript
Raw Normal View History

import { UserPermissionRole } from "@prisma/client";
import type { NextApiRequest } from "next/types";
export const isAdminGuard = async (req: NextApiRequest) => {
const { userId, prisma } = req;
2022-06-08 16:52:25 +00:00
const user = await prisma.user.findUnique({ where: { id: userId } });
return user?.role === UserPermissionRole.ADMIN;
};