21 lines
570 B
TypeScript
21 lines
570 B
TypeScript
import { prisma } from "@repo/db";
|
|
import { Error } from "_components/Error";
|
|
import { getServerSession } from "api/auth/[...nextauth]/auth";
|
|
|
|
export default async ({ children }: { children: React.ReactNode }) => {
|
|
const session = await getServerSession();
|
|
|
|
if (!session) return <Error title="Nicht eingeloggt" statusCode={401} />;
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: {
|
|
id: session.user.id,
|
|
},
|
|
});
|
|
|
|
if (!user?.permissions.includes("ADMIN_STATION"))
|
|
return <Error title="Keine Berechtigung" statusCode={403} />;
|
|
|
|
return <>{children}</>;
|
|
};
|