Dispatch Router-Struktur; AddPenalty Layout gefixed
This commit is contained in:
57
apps/dispatch/app/(app)/layout.tsx
Normal file
57
apps/dispatch/app/(app)/layout.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { Metadata } from "next";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getServerSession } from "api/auth/[...nextauth]/auth";
|
||||
import { Error } from "_components/Error";
|
||||
import { prisma } from "@repo/db";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "VAR: Pilot",
|
||||
description: "Die neue VAR Leitstelle.",
|
||||
};
|
||||
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const session = await getServerSession();
|
||||
const openPenaltys = await prisma.penalty.findMany({
|
||||
where: {
|
||||
userId: session?.user.id,
|
||||
until: {
|
||||
gte: new Date(),
|
||||
},
|
||||
suspended: false,
|
||||
type: { in: ["TIME_BAN", "BAN"] },
|
||||
},
|
||||
});
|
||||
|
||||
if (!session) {
|
||||
console.log(session);
|
||||
return redirect("/logout");
|
||||
}
|
||||
|
||||
if (openPenaltys[0]) {
|
||||
if (openPenaltys[0].type === "BAN") {
|
||||
return (
|
||||
<Error
|
||||
title="Du wurdest permanent ausgeschlossen"
|
||||
statusCode={403}
|
||||
description={`Dein Fehlverhalten war so schwerwiegend, dass du dauerhaft von VirtualAirRescue ausgeschlossen wurdest. Du kannst im Hub weitere Informationen finden.`}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Error
|
||||
title="Du hast eine aktive Strafe"
|
||||
statusCode={403}
|
||||
description={`Du bist bis zum ${new Date(openPenaltys[0].until!).toLocaleString()} gesperrt. Du kannst im Hub weitere Informationen finden.`}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!session.user.emailVerified) {
|
||||
return <Error title="E-Mail-Adresse nicht verifiziert" statusCode={403} />;
|
||||
}
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user