2022-06-23 22:26:40 +00:00
|
|
|
import { UserPermissionRole } from "@prisma/client";
|
2022-06-23 22:46:42 +00:00
|
|
|
import type { NextApiRequest } from "next/types";
|
2022-06-01 15:05:33 +00:00
|
|
|
|
2022-06-23 22:26:40 +00:00
|
|
|
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 } });
|
2022-05-31 18:46:09 +00:00
|
|
|
return user?.role === UserPermissionRole.ADMIN;
|
2022-05-31 16:33:01 +00:00
|
|
|
};
|