Files
car-crushers-portal/pages/mod-queue.page.server.tsx

48 lines
980 B
TypeScript

export async function onBeforeRender(pageContext: PageContext) {
const { current_user: currentUser } = pageContext;
if (!currentUser)
return {
pageContext: {
logged_in: false,
},
status: 401,
};
const typePermissions = {
appeal: [1 << 0, 1 << 1],
gma: [1 << 5],
report: [1 << 5],
};
const { searchParams } = new URL(
pageContext.urlOriginal,
"http://localhost:8788"
);
const allowedTypes = [];
for (const [type, ints] of Object.entries(typePermissions)) {
if (ints.find((i) => currentUser.permissions & i)) allowedTypes.push(type);
}
if (!allowedTypes.length)
return {
pageContext: {
allowedTypes,
},
status: 403,
};
const includeClosed = searchParams.get("includeClosed");
const type = searchParams.get("type");
const sort = searchParams.get("sort") ?? "asc";
return {
pageContext: {
pageProps: {
allowedTypes,
},
},
};
}