mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-07-04 17:30:52 +00:00
31 lines
612 B
TypeScript
31 lines
612 B
TypeScript
|
import prisma from "@/lib/prisma";
|
||
|
import { auth, signIn } from "@/lib/auth";
|
||
|
import { redirect } from "next/navigation";
|
||
|
|
||
|
interface AdminProtectedLayoutProps {
|
||
|
children: React.ReactNode;
|
||
|
}
|
||
|
|
||
|
export const AdminProtectedLayout = async ({
|
||
|
children,
|
||
|
}: AdminProtectedLayoutProps) => {
|
||
|
const session = await auth();
|
||
|
const userId = session?.user?.id;
|
||
|
if (!userId) {
|
||
|
await signIn();
|
||
|
}
|
||
|
|
||
|
const user = await prisma.user.findUnique({
|
||
|
select: {
|
||
|
role: true,
|
||
|
},
|
||
|
where: {
|
||
|
id: userId,
|
||
|
},
|
||
|
});
|
||
|
|
||
|
if (user?.role !== "ADMIN") redirect("/unauthorized");
|
||
|
|
||
|
return <>{children}</>;
|
||
|
};
|