next/lib/server/middlewareButNotReally/isAdmin.ts

13 lines
344 B
TypeScript
Raw Normal View History

2023-10-03 00:33:54 -04:00
import { H3Event, EventHandlerRequest } from "h3";
import { messages } from "../constants";
import isLoggedIn from "./isLoggedIn";
2023-10-03 00:33:54 -04:00
export default function (ev: H3Event<EventHandlerRequest>) {
isLoggedIn(ev);
2023-10-03 00:33:54 -04:00
if (!ev.context.currentUser?.profile.isAdmin) {
throw createError({
statusCode: 403,
statusMessage: messages[403],
});
}
}