next/lib/server/middlewareButNotReally/isAdmin.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ c27c81f39c
refactor(api/utils): update isAdmin check
make it also check that the user is logged in; eliminates need to type `isLoggedIn()` on the previous line
2023-12-06 21:37:54 -05:00

13 lines
344 B
TypeScript

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